News for hackers. Stuff that matters.
Re:Some Thoughts on Zig by agentultra on Thursday July 21, 2022 @10:47PM (#32187891)
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.
Re:Some Thoughts on Zig by pjmlp on Friday July 22, 2022 @02:14AM (#32189082)
Turbo Pascal 6.0 manual from 1990, page 210

http://www.bitsavers.org/pdf/borland/turbo_pascal/Turbo_Pasc...

What is old is new again. :)

Re:Some Thoughts on Zig by Tozen on Friday July 22, 2022 @12:47PM (#32194115)
> What is old is new again.

Truth!

Re:Some Thoughts on Zig by kaba0 on Friday July 22, 2022 @03:03AM (#32189345)
How 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.

Re:Some Thoughts on Zig by alphazino on Friday July 22, 2022 @03:21AM (#32189455)
Yes, 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.

Re:Some Thoughts on Zig by zozbot234 on Friday July 22, 2022 @03:24AM (#32189467)
Rust is getting custom/local allocators as well.
Re:Some Thoughts on Zig by alphazino on Friday July 22, 2022 @03:33AM (#32189502)
Do you have any links about that?

I did a quick search but didn't find anything substantial.

Re:Some Thoughts on Zig by kaba0 on Friday July 22, 2022 @10:36AM (#32192283)
Re:Some Thoughts on Zig by AnIdiotOnTheNet on Friday July 22, 2022 @08:01AM (#32191020)
Unfortunately 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.