logoalt Hacker News

WD-42yesterday at 5:39 AM7 repliesview on HN

All necessary memory is allocated at initialization. The application is not allowed any allocations during it's normal runtime. This is how it avoid memory bugs.

Not a lot of people write programs this way.


Replies

physicsguyyesterday at 7:29 AM

Static memory allocation is widely used in quite a bit of embedded software, particularly safety critical stuff. There it's often latency related since you don't want hangs while memory is allocated.

I've even seen it on some simulation software's core that was written in the 80s originally; at the time memory was much more constrained so allocating upfront meant you could check upfront whether the simulation could actually run or not vs crashing out part way through.

show 1 reply
ahokayesterday at 6:37 AM

A lot of people write software like this when predictable latency is a hard requirement.

show 1 reply
n6242yesterday at 7:24 AM

I was just learning yesterday that's exactly what GTA did on PS2, which I thought was interesting. (Not to belittle your point, just giving an example)

show 1 reply
NothingAboutAnyyesterday at 7:18 AM

I do this in Unity because allocations/GC cause hitches. it's pretty normal thing to do there's even the built in pooling libraries so you can pre-allocate 10,000 gameobjects when the game starts. I haven't played with ECS/DOTS yet but I assume it does something similar.

pton_xdyesterday at 6:49 AM

This is standard practice in the games industry.

tovejyesterday at 1:08 PM

I do. The only thing I need dynamic allocations for is queues of asynchronous events, and that's just because I'm too lazy to calculate an upper bound for how many there may be.