Passing a JS ArrayBuffer or TypedArray to Emscripten w/o Copying
If my C/C++ function takes an
std::string as in:
void processBuffer(std::string const& buffer)
I can get the data, but IIUC, the conversion to
std::string will incur a copy of the buffer.
Is there a way to pass the raw buffer without a copy?
My access is strictly read-only.
void processBuffer(const char* str, size_t size);
allow_raw_pointers() in the
EMSCRIPTEN_BINDINGS, but this does not seem to work.
What am I missing?
As it currently stands, there is no way to allow the emscriptened C/C++ code to access JS allocated memory buffers.
That being said, buffers allocated via
Module._malloc() can be passed “by pointer” when using the C API.
Embinding will add additional copying into the C++ types.
For more info see this thread on the emscripten mailing list.