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?
Wasm doesn't have a way to shrink the linear memory again.
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?
From the host's perspective there are no "pieces" of memory smaller than an entire "linear memory"
I don't believe individual linear memories within a Store
can be freed until the entire Store
is dropped
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
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 free
ing will give that growth back to the host
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?
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
Awesome I will take a look at the repo. Thank you very much!
Cwasi4wasm has marked this topic as resolved.
Last updated: Dec 23 2024 at 12:05 UTC