Elaborate the usage of `memoryBase` flag with examples
In the code examples of Reading and Writing Graphics and Reading and Writing Audio, there is a comment NOTE: Be sure to set a correct --memoryBase when when writing to memory directly like we are here. It would be nice if there is an example showing what is a correct value for the flag. I read similar issue #103 but the link to the doc doesn't really help me.
I would be happy to create a PR to further explain it after I understand the usage but I am still trying to figure it out. Your guidance on this matter would be appreciated.
@hangindev Ah! Thank you very much for calling this out! :smile:
So the memoryBase flag has to do with the way AssemblyScript allocates memory in the WebAssembly Linear memory. For example, here is the flag in the AssemblyScript docs:
https://www.assemblyscript.org/memory.html#memory-regions
As a general TL;DR: Let's say you needed 100 bytes of memory. You would do --memoryBase 100 if I am not mistaken. Because that means if you do something like make an array, or a string in AssemblyScript. Instead of using the first 100 bytes which you've reserved for manual memory management, the AssemblyScript runtime will use everything after that :smile:
Let me know if that helps explain things! Thanks! :smile: