-
Notifications
You must be signed in to change notification settings - Fork 34
alloc()
function
#32
Comments
Is there an example of a Zig project that does that? |
Hi! All of them :) https://ziglang.org/documentation/0.7.1/#Memory There is no such thing as a global allocator. Application can choose whatever they want every time a function requiring dynamic allocation is called. Such an allocator can be a preallocated fixed buffer, an arena, a debugging allocator, etc. This gives a lot of control and allows for very efficient memory usage. We did something similar at Fastly; I wrote a blurb about this: https://www.fastly.com/blog/webassembly-memory-management-guide-for-c-rust-programmers |
But maybe an alternative would be for the guest to provide a fixed-size buffer, as well as the size. The This allows the guest to do whatever they want in order to store the incoming data. |
#43 was merged, which no longer required an |
Hi!
Memory allocations currently rely on exporting an
alloc()
function.While this works for Rust, it doesn't play well with Zig, that doesn't hide memory allocations (any function requiring dynamic allocations must accept an allocator as a parameter). This is not going to play well with GC'd languages either.
Maybe the application could call an initialization function, passing a function pointer to the allocation function instead?
The text was updated successfully, but these errors were encountered: