Hacker News new | past | comments | ask | show | jobs | submit login

Can somebody eli5 what this really means? Specifically, how is code without dynamic allocation bring about predictability?



In addition to the mentioned known maximum memory, it also has useful performance characteristics. global memory allocators, by their nature can create allocation patterns and layouts that can be very sensitive thing like startup conditions, long-runtimes, or exact inter-thread execution sequences. This can cause items that in one run that get allocated near each other, can be allocated very distantly, or chaotically in the heap in another run, for instance.

Now, given that modern CPUs rely heavily on their cache lines/hierarchies, branch predictors, and prefetchers, changes in layouts can have significant performance implications, algorithms that run quickly when things are contiguous in memory, can run orders of magnitudes slower on layouts that are more random, and have more cache line miss. And those layouts are often the result of long run-times in dynamically allocated systems, due to accumulated heap fragmentation.

Now, static allocation neither completely solves these problems, nor is it the only solution, but it is the case that the techniques that are used for static allocation, often have tremendous benefit for cache layout, and combined with other added benefits, like reduced OOM conditions, it's a powerful constraint.

Edit: Not to mention that the previously noted heap fragmentation can also cause eventual failure to allocation conditions, even without true memory exhaustion.


Dynamic allocation can fail. Memory can become fragmented or you could just exceed your budget.


It brings predictability because know you won’t run out of memory. If everything is statically allocated, the total amount of memory the application will use is known at compile time. Very important for memory restricted systems.




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

Search: