[TIMOB-28039] Android: Make use of shared underlying byte array in Ti.Buffer
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | High |
| Status | Open |
| Resolution | Unresolved |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Android |
| Labels | n/a |
| Reporter | Christopher Williams |
| Assignee | Unknown |
| Created | 2020-07-23T17:11:27.000+0000 |
| Updated | 2020-07-23T17:11:44.000+0000 |
Description
Our current API for Ti.Buffer makes use of a
byte[]. While https://github.com/appcelerator/titanium_mobile/pull/11810 helps us to copy those bytes out to an ArrayBuffer on the JS side (though Ti.Blob), we should consider retooling Ti.Buffer to use a ByteBuffer with direct allocation pointing to the same exact memory shared by the JS engine's ArrayBuffer.
This blog post makes reference to how the J2V8 project did exactly this: https://eclipsesource.com/blogs/2016/07/25/typedarrays-sharing-memory-between-v8-and-java/
Essentially this would involve Ti.Buffer wrapping a ByteBuffer rather than a byte[]. We could then read/write to the bytes from the native or JS side **without** crossing the JNI/V8 native bridge.
No comments