Stream: wasm

Topic: ✔ Global Allocator and dealloc


view this post on Zulip Cwasi4wasm (Jun 15 2023 at 18:17):

Does the Global Allocator immediately give back memory to the wasm engine once a deallocation or drop trait is triggered? If not are they any other allocators you can recommend that are more aggressive?

view this post on Zulip bjorn3 (Jun 15 2023 at 18:41):

Wasm doesn't have a way to shrink the linear memory again.

view this post on Zulip Cwasi4wasm (Jun 15 2023 at 18:46):

I was thinking more of reuse not shrinking. If I free up a pice of memory can wasm reuse it if it has been freed?

view this post on Zulip Lann Martin (Jun 15 2023 at 18:49):

From the host's perspective there are no "pieces" of memory smaller than an entire "linear memory"

view this post on Zulip Lann Martin (Jun 15 2023 at 18:51):

I don't believe individual linear memories within a Store can be freed until the entire Store is dropped

view this post on Zulip Cwasi4wasm (Jun 15 2023 at 19:04):

Okay I think its becoming more clear. I guess my last question would be would be that I see wasm-bindgen has a _wbindgen_malloc for allocation of memory using the alloc in std and _wbidgen_dealloc using dealloc. In this scenario is the dealloc useless since that memory cannot be reused? Thank you for response just trying to understand how this works

view this post on Zulip Lann Martin (Jun 15 2023 at 19:07):

Guests control their own allocation within a linear memory. You can definitely free and reuse memory from the guest perspective (assuming the guest allocator supports that), its just that if a new allocation causes the linear memory to grow then no amount of guest freeing will give that growth back to the host

view this post on Zulip Cwasi4wasm (Jun 15 2023 at 19:10):

I guess I should have clarified I was talking about the guest memory this make sense now, thank you. Is the default rust global allocator good for this?

view this post on Zulip Lann Martin (Jun 15 2023 at 19:13):

I believe you'll usually end up with dlmalloc for wasm32 targets. I don't know exactly how it works but I'm sure it reuses free'd memory

view this post on Zulip Cwasi4wasm (Jun 15 2023 at 19:16):

Awesome I will take a look at the repo. Thank you very much!

view this post on Zulip Notification Bot (Jun 15 2023 at 19:16):

Cwasi4wasm has marked this topic as resolved.


Last updated: Nov 22 2024 at 17:03 UTC