GitHub user breautek added a comment to the discussion: Pass memory references 
from Android Native (C++) to Javascript and read data.

> Is there a way I can access this memory from javascript (ArrayBuffer) without 
> having to copy the values?

No not really. The JS engine memory is isolated and not accessible from outside 
the engine. So if wanted to actually read or manipulate the memory in JS, the 
memory needs to be copied. If this was a NodeJS environment, the answer will be 
kind of different but webview JS environments has no concept of native c/c++ 
addons (even with the introduction of WASM). This includes the android webview 
/ wkwebview on iOS.

It would likely be better to keep all memory access/manipulation done on the 
native side. You can pass that "pointer" to the JS as a way to keep context.

If you do this, it is important to note that JS numbers are 64-bit doubles... 
the integer is represented with 53-bits. This means that JS engines cannot 
safely represent the full range of a long (64-bit) integer. Therefore if you do 
pass the pointer to JS, it must be passed as a string, and then when passing 
back to native, the native should parse the string back to a long value. 
Failure to do this could cause "floating-point errors" on your pointer on the 
JS side, resulting in the pointer becoming corrupted and pointing at some other 
memory space instead.

A cordova plugin could maybe be crafted so that you can have a JS 
representation of your context and APIs to do manipulations on that memory, 
without passing or copying that memory through the cordova bridge... though 
kinda depends on your actual use cases.

GitHub link: 
https://github.com/apache/cordova/discussions/487#discussioncomment-10097887

----
This is an automatically sent email for issues@cordova.apache.org.
To unsubscribe, please send an email to: issues-unsubscr...@cordova.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to