Emscripten emulates the heap by allocating a large JS typed array and using pointers/memory addresses as indexes into this heap. This works very good and allows for very fast constant time pointer operations. Most JS engines should be able to optimize that code so that the generated runtime assembly looks pretty much exactly like the compiled C code would look like.
However, this direct usage of addresses as array index does have a significant limitation: it does not allow us to map arbitrary linear data into the Emscripten heap. E.g. I have a typed array in JS-land and want to pass it to a function in C-land. I will first need to copy that data into the Emscripten heap before I can get a pointer to it and pass it to the C-function. Of course I can circumvent this by getting a subarray of the Emscripten heap and use this as my typed array in JS land in the beginning. The problem with this is, that one of the most common use-cases for this would be loading a file from disk or a web request. The browser APIs however (e.g. FileReader) do not allow you to specify the target ArrayBuffer/TypedArray to load the file into, but will always allocate a new one. If I load a file using FileReader, there is no way to get a "pointer" to that array buffer that's outside the Emscripten heap. I need to copy the entire file into the Emscripten heap to get a pointer to that files data. It would be nice to be able to map any ArrayBuffer/TypedArray into the Emscripten address space without having to copy the entire buffer. For functions we already have this functionality in the form of Runtime.addFunction. Something similar would be nice to have especially for IO intensive applications. It would require any access to the Emscripten heap to be wrapped in a function call that checks if the address is a virtual address that is mapped to a buffer outside the Emscripten heap. This would most certainly cause a performance regression regarding memory access speed. I believe some applications could still benefit from this. Of course it could be controlled by a compiler flag and be switched off by default. What do you guys think?
--
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-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Yeah, this is certainly a concern. But what do you mean to "map" binary data in to the emscripten heap? Copy it, or do something more dynamic?In general, I think the solution is to get web APIs to be able to write into existing typed arrays. For example we should be able to do an XHR and tell it to write into this buffer at that position, and give us a callback when it's done. (I don't know if this has been proposed, but I'll try to find someone to ask.)
- Alon
--On Fri, Nov 15, 2013 at 12:21 PM, Daniel Baulig <daniel...@gmx.de> wrote:
Emscripten emulates the heap by allocating a large JS typed array and using pointers/memory addresses as indexes into this heap. This works very good and allows for very fast constant time pointer operations. Most JS engines should be able to optimize that code so that the generated runtime assembly looks pretty much exactly like the compiled C code would look like.--
However, this direct usage of addresses as array index does have a significant limitation: it does not allow us to map arbitrary linear data into the Emscripten heap. E.g. I have a typed array in JS-land and want to pass it to a function in C-land. I will first need to copy that data into the Emscripten heap before I can get a pointer to it and pass it to the C-function. Of course I can circumvent this by getting a subarray of the Emscripten heap and use this as my typed array in JS land in the beginning. The problem with this is, that one of the most common use-cases for this would be loading a file from disk or a web request. The browser APIs however (e.g. FileReader) do not allow you to specify the target ArrayBuffer/TypedArray to load the file into, but will always allocate a new one. If I load a file using FileReader, there is no way to get a "pointer" to that array buffer that's outside the Emscripten heap. I need to copy the entire file into the Emscripten heap to get a pointer to that files data. It would be nice to be able to map any ArrayBuffer/TypedArray into the Emscripten address space without having to copy the entire buffer. For functions we already have this functionality in the form of Runtime.addFunction. Something similar would be nice to have especially for IO intensive applications. It would require any access to the Emscripten heap to be wrapped in a function call that checks if the address is a virtual address that is mapped to a buffer outside the Emscripten heap. This would most certainly cause a performance regression regarding memory access speed. I believe some applications could still benefit from this. Of course it could be controlled by a compiler flag and be switched off by default. What do you guys think?
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-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
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-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
--
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+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
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+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
For more options, visit https://groups.google.com/d/optout.To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.