There isn't a way to let compiled code access a new ArrayBuffer. The
compiled code has hardcoded access to the wasm Memory it was instantiated
with - all the pointers it can understand are indexes into that Memory. It
can't refer to anything else, I'm afraid.

In the future using different address spaces or techniques with reference
types may open up some possibilities here.

(The other direction, accessing data in the wasm Memory from the outside
without copying, is possible, doing a .subarray() on a typed array view on
that memory. That's how the WebGL bindings etc. work.)


On Thu, Jan 9, 2020 at 10:09 AM キャロウ マーク <[email protected]> wrote:

> I have tried and failed to find some documentation about using
> emscripten::val to transfer data in an ArrayBuffer to a c++ function
> compiled to .wasm.
>
> I found an example from which I took the lines shown below
>
>        static texture createFromMemory(const emscripten::val& data)
>        {
>            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);
>            …
>        }
>
> but it looks to me as if this is copying that data from the ArrayBuffer to
> the std::vector.
>
> Is is possible to get a pointer to the data for use by the c++ side
> without copying, either with embind or with the idl binder? The textures
> I’m working with here can be *very* large.
>
> Regards
>
>     -Mark
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/B97FFC45-FAED-4413-9558-4A6A0BF7287B%40callow.im
> <https://groups.google.com/d/msgid/emscripten-discuss/B97FFC45-FAED-4413-9558-4A6A0BF7287B%40callow.im?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpQVCtbnYqDS4POCdCc6seLqs11sRks2hjhdR2EuUqQ6Qg%40mail.gmail.com.

Reply via email to