Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wasm] Emscripten typed_memory_view #103

Open
bkotsopoulossc opened this issue Aug 24, 2022 · 1 comment
Open

[Wasm] Emscripten typed_memory_view #103

bkotsopoulossc opened this issue Aug 24, 2022 · 1 comment
Assignees

Comments

@bkotsopoulossc
Copy link
Contributor

We have code in DataView_wasm.hpp and djinni_wasm.cpp that creates a JS Uint8Array view of memory on the wasm heap:

static auto uint8ArrayClass = em::val::global("Uint8Array");

unsigned addr = reinterpret_cast<unsigned>(buffer.data());
unsigned size = static_cast<unsigned>(buffer.size());
em::val uint8ArrayObj = uint8ArrayClass.new_(getWasmMemoryBuffer(), addr, size);

return uint8ArrayObj;

The Uint8Array view is used regardless of the data type in C++ - whether it is std::vector<uint8_t> or std::string.

Emscripten offers a dedicated API for this - typed_memory_view, should we be using it? Is it more reliable or performant?

return em::val view(em::typed_memory_view(buffer.size(), buffer.data()));
@li-feng-sc
Copy link
Contributor

I think that does the same thing:
https://github.com/emscripten-core/emscripten/blob/f6fa2ec09b650838bdb8cda689f28e1ce0f15788/src/embind/embind.js#L911

Regarding the "typed" part, we won't get element type unless we turn the dataview type into a generic one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants