The most efficient way is to send the pointer into EM_ASM, then do reads
directly to memory using the right offsets, but that requires using
information about how the data is laid out in memory (on the plus side, the
alignment rules are the natural 32-bit ones, with fully aligned doubles).

Otherwise multiple calls into EM_ASM adds overhead, but in many cases it
wouldn't be noticeable.

On Mon, Sep 19, 2016 at 1:57 PM, Robert Goulet <robert.gou...@autodesk.com>
wrote:

> Hi,
>
> How do we pass an array of objects to Javascript function from C?
>
> Consider the following example:
>
> struct data {
>     double a;
>     int b;
>     unsigned char c;
> };
>
> std::vector<data> my_data;
>
> EM_ASM_ARGS({
>     var data_array = ???
>     process_data(data_array);
> }, my_data);
>
> Is this possible? I couldn't find any clear documentation about this topic.
>
> For the moment I've used the following workaround, but it doesn't look
> super efficient:
>
> for( auto const & i : my_data ) {
>     EM_ASM_ARGS({
>         process_data($0, $1, $2);
>     }, i.a, i.b, i.c);
> }
>
> Thanks!
>
> --
> 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 emscripten-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 emscripten-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to