logoalt Hacker News

Laremeretoday at 1:39 PM1 replyview on HN

Several things:

* There are many useful ways to handle it properly, and your choice depends on your program's constraints. The very small amount of friction (once you're used to it) encourages you to consider what ways to handle it are viable, such as allocating all memory at startup.

* If your strategy is to crash immediately, there is very little additional friction but you get the benefit of it being obvious in your code that this is the case.

* There are environments where memory allocation fails immediately, including if you turn off over-commit on Linux. If your hardware is dedicated to running a high reliability system, configuring it in this way is reasonable.

* Memory is not the only resource. Indeed, removing the special call out is what changed here. That different resources are handled with the same mechanism (errors, instead of eg returning null from malloc) is good.


Replies

Panzerschrektoday at 1:55 PM

Autors of Zig did a choice for me. I can't use RAII in it. In C++ it's better - when I don't care, I just use standard library containers, when I do care, I can bypass them.