Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elaborate the usage of memoryBase flag with examples #123

Open
hangindev opened this issue May 1, 2021 · 1 comment
Open

Elaborate the usage of memoryBase flag with examples #123

hangindev opened this issue May 1, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@hangindev
Copy link
Contributor

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.

@torch2424 torch2424 self-assigned this May 4, 2021
@torch2424 torch2424 added the bug Something isn't working label May 4, 2021
@torch2424
Copy link
Owner

@hangindev Ah! Thank you very much for calling this out! 😄

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 😄

Let me know if that helps explain things! Thanks! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants