Questions about memory views

9 views
Skip to first unread message

キャロウ マーク

unread,
Jan 10, 2020, 12:29:58 PM1/10/20
to emscripten-discuss
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#memory-views talks about memory views but leaves much unsaid. Where can I find complete documentation? I’m looking for information about all the possible arguments to the constructor in usage such as

std::vector<uint8_t> bytes{};
bytes.resize(data["byteLength"].as<size_t>());
emscripten::val memory = emscripten::val::module_property("HEAP8")["buffer"];
emscripten::val memoryView = data["constructor"].new_(memory, reinterpret_cast<uintptr_t>(bytes.data()), data["length"].as<uint32_t>());
memoryView.call<void>("set", data);

(This usage isn’t even mentioned on the referenced page.)

In particular I want to know if there is a way to give an offset to either the view constructor or the set method so that “data” gets copied into just part of the bytes vector.

I also want to know how in usage such as

std::vector<uint8_t> cDst;
cDst.resize(bytes_per_slice);

/* Write data to cDst vector …. */

return val(typed_memory_view(cDst.size(), cDst.data());

the receiver in JS can delete the data when done with it.

Regards

-Mark
signature.asc
Reply all
Reply to author
Forward
0 new messages