Reputation: 13
I am currently learning about web assembly, using C++ and the emscripten toolchain. I understand how memory works with the stack and the heap in C++, as well as that web assembly uses a contiguous memory buffer that can be a max size of 4GB (or whatever the browser allows). Is there a max size for allocating data on the stack in C++ within web assembly, and is it different than the max memory size. For example can I allocate all of my data in C++ on the stack, and be able to use the max memory, or should I be allocating my data on the heap, and manage it myself (with smart pointers)?
Upvotes: 1
Views: 1040
Reputation: 3663
I think total memory (TOTAL_MEMORY option) includes both stack and heap space.
You have the TOTAL_STACK= option that allow to change the size reserved to the stack. 5MB by default.
Regarding memory usage, you should simply do what you would do in regular C++ code: sometimes things are better on the stack, sometimes better with smart pointers or other managed heap memory strategies, sometimes just manual new/delete.
Upvotes: 2