4 ms·
Another thing which makes Zig interesting is it’s approach to allocation, making a failure to allocate memory a catchable error, and enabling developers to easi
by agentultra 4y ago
Another thing which makes Zig interesting is it’s approach to allocation, making a failure to allocate memory a catchable error, and enabling developers to easily assign their own allocators.
- pjmlp 4y agoTurbo Pascal 6.0 manual from 1990, page 210 http://www.bitsavers.org/pdf/borland/turbo_pascal/Turbo_Pascal_Version_6.0_Programmers_Guide.pdf http://www.bitsavers.org/pdf/borland/turbo_pascal/Turbo_Pasc... What is old is new again. :)
- Tozen 4y ago> What is old is new again. Truth!
- kaba0 4y agoHow can it guarantee that the OS doesn’t just lie about having allocated that space? As far as I know they are unallocated until a write to a given page (by default on Linux at least), and thus any write could potentially fault. Unless it zeros every page it allocated, I don’t see it being able to defend against it in practice.
- alphazino 4y agoYes, but I think you missed the point of the parent comment. > enabling developers to easily assign their own allocators Through a combination of Zig's convention to pass around allocators instead of using a global allocator, the allocator interface's ability to return errors, and the Zig language forcing you to handle all errors (unless you explicitly discard them), a lot of Zig code is written with allocation failure in mind. This means that you can seamlessly pass a custom allocator, say a bump allocator backed by a fixed buffer, to a function in some third-party library and still handle the case where the buffer runs out of space.
- zozbot234 4y agoRust is getting custom/local allocators as well.
- AnIdiotOnTheNet 4y agoUnfortunately no, there's nothing that can be done about an ABI that insists on lying to you. This is one of the reasons I think the Linux default is a really terrible idea.