Directly accessing HEAP32 will definitely be much faster than the very
generic getValue() function. If you don't need any of the genericity of
what getValue() offers, using HEAP32 is definitely recommended.

2016-09-20 23:27 GMT+03:00 Robert Goulet <robert.gou...@autodesk.com>:

> Thanks jj, I ended up using getValue on the JS side to get the data from
> the pointer I pass from C. Is there any performance concerns with this or
> should I use HEAP32 instead?
>
> On Tuesday, September 20, 2016 at 12:33:01 PM UTC-4, jj wrote:
>>
>> The src/library_xxx.js files are generally good examples.
>>
>> Here's one snippet where C function passes a pointer to an integer array
>> and length of that array to JS side, and JS code reads through the array:
>> https://github.com/kripken/emscripten/blob/master/src/librar
>> y_openal.js#L329. If not using JS code that lives in js-libraries, the
>> i32 {{{ makeGetValue }}} can be replaced with a direct HEAP32[pointer >> 2].
>>
>> Another example with filling a struct in JS side:
>> https://github.com/kripken/emscripten/blob/master/src/librar
>> y_html5.js#L180
>>
>> and reading the fields from a pointer to a struct:
>> https://github.com/kripken/emscripten/blob/master/src/librar
>> y_html5.js#L1728
>>
>>
>>
>> 2016-09-20 16:45 GMT+03:00 Robert Goulet <robert...@autodesk.com>:
>>
>>> Do you have an example of sending pointer into EM_ASM and reading it
>>> directly from memory?
>>>
>>> In my case I am calling EM_ASM close to a thousand times to pass engine
>>> profiling data to javascript for drawing on the web page, so I am trying to
>>> avoid adding time to the profiling result. If EM_ASM does add overhead,
>>> then I hope to reduce it by calling it only once instead of a thousand
>>> times per frame. I profiled it to about ~2.5ms per frame to do these
>>> thousand calls to EM_ASM, which is a lot if you consider the actual frame
>>> time is <= 17ms.
>>>
>>> On Monday, September 19, 2016 at 5:45:21 PM UTC-4, Alon Zakai wrote:
>>>>
>>>> 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...@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.
>>>
>>
>> --
> 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