The curious case of a memory leak in a Zig program
iamkroot.github.io
The curious case of a memory leak in a Zig program
1–10 of 80 posts
Re: The curious case of a memory leak in a Zig program
#2Re: The curious case of a memory leak in a Zig program
#3Re: The curious case of a memory leak in a Zig program
#4TL;DR: the author had to figure out the hard way that Zig's FixedBufferAllocator is a bump allocator, and that it doesn't reuse freed memory except when it's the last allocation.
Re: The curious case of a memory leak in a Zig program
#5TL;DR: the author had to figure out the hard way that Zig's FixedBufferAllocator is a bump allocator, and that it doesn't reuse freed memory except when it's the last allocation.
Re: The curious case of a memory leak in a Zig program
#6TL;DR: the author had to figure out the hard way that Zig's FixedBufferAllocator is a bump allocator, and that it doesn't reuse freed memory except when it's the last allocation.
What an awful API design choice. It’s a stack allocator that leaks your memory if you don’t free in reverse order. Why would anybody ever want that behavior, let alone as the default?
Re: The curious case of a memory leak in a Zig program
#7TL;DR: the author had to figure out the hard way that Zig's FixedBufferAllocator is a bump allocator, and that it doesn't reuse freed memory except when it's the last allocation.
What an awful API design choice. It’s a stack allocator that leaks your memory if you don’t free in reverse order. Why would anybody ever want that behavior, let alone as the default?
This makes this allocator fast, but it should clearly be named/described I agree.
Re: The curious case of a memory leak in a Zig program
#8Earlier quoted context omitted.
What an awful API design choice. It’s a stack allocator that leaks your memory if you don’t free in reverse order. Why would anybody ever want that behavior, let alone as the default?
Because this is a specific allocator different from the general purpose allocator which is the "default" option. It is aimed at some specific use cases, when developers want to fine-tune their allocation strategies.
Re: The curious case of a memory leak in a Zig program
#9Earlier quoted context omitted.
Because this is a specific allocator different from the general purpose allocator which is the "default" option. It is aimed at some specific use cases, when developers want to fine-tune their allocation strategies.
I get that it is a specific allocator for niche use cases but i think it would be better that free throws some exception if it is done out of order rather than just being a no-op and making the programmer figure it out.
But it should be clearly spelled out.
When your type is already called
FixedBufferAllocator
You can probably extend it to FixedBufferBumpAllocator
And now the implications are more searchable and clearer.