Re:What is malloc doing, anyway?
by smashspectacle on Monday November 09, 2026 @09:35AM
(#50426220)
This is actually what first drew me to zig. Most people talk about error handling, but the explicit allocator handling and making choosing an allocator a deliberate consideration has pushed me to better coding habits in general. I don't think it is possible or practical to completely abandon heap-allocated memory, but explicitly choosing between allocation types and styles that most precisely fit a job has great potential for meeting that spirit.
[ Parent
| on HN ]
I don't think we can get rid of heap memory, but I do think we can get rid of a shared heap.
Isn't a shared heap pretty much the difference between multithreading and multiprocessing? Won't it turn every form of thread synchronization into a remote procedure call?
Re:What is malloc doing, anyway?
by dreamcompiler on Monday November 09, 2026 @03:35PM
(#50431674)
You can definitely avoid heap-allocated memory; early versions of Fortran could not do dynamic memory allocation at all. You basically had to preallocate giant arrays and build your own memory manager. It was sheer hell but it worked.
To me the value of zig's approach is in being able to control the allocations that happen in (library) code. When you call a C function, all kinds of heap allocations may happen between the callee and malloc, even if the return value of the call is in caller-allocated memory. With zig, you can pass a local (arena) allocator instead and avoid uncontrolled global allocations.