Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Also to clarify: there are platforms (like linux) which de facto have nonfailable allocation, if you run out of memory the system will oom kill your process, and neither zig nor rust will save you from that.

I believe In practice the most common place where failable OOM is a big deal is in embedded systems programming



No language can save you from OOMs, but because Zig pervasively uses explicit memory allocation, it makes it easy to greatly mitigate OOM risks by front-loading all the fallibility:

1. Calculate and allocate all your required memory immediately upon process startup (including memory from OS resources like sockets)

2. Call mlockall to prevent the pages from being swapped out

3. Write "-1000" to /proc/self/oom_score_adj to avoid the OOM killer

4. Use your preallocated memory as a pool for all further allocations

With the above approach, the application has full control over how to handle application-level OOMs (e.g. applying backpressure to connecting clients, or shrinking non-critical caches) once it is past the start-up stage.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: