logoalt Hacker News

Static Allocation, Constant Work

86 pointsby surprisetalkyesterday at 5:30 PM14 commentsview on HN

Comments

mrkeentoday at 7:49 PM

> TigerStyle: All memory must be statically allocated at startup. No memory may be dynamically allocated (or freed and reallocated) after initialization. This avoids unpredictable behavior that can significantly affect performance, and avoids use-after-free.

Maybe maintaining an array of NULL-orders satisfies the letter of the "no dynamic allocation" law, but I'm not convinced it satisfies the spirit.

Haven't you just written a buffer of NULL-orders, which you proceed to loan out to callers (i.e. "allocate" and "reallocate"?).

Someone else's battle-hardened allocator might be slow or buggy, so you write your own as part of the business logic implementation?

show 1 reply
SPascareli13today at 6:29 PM

I never fully understood how to work with this "reserved" values being valid instead of errors when you can't allocate more memory, in either case you still need to check if you have a real entity or a reserved/error, right? Does it really make things simpler?

show 2 replies
pjmlptoday at 7:01 PM

Interesting how everyone keeps rediscovering 8 and 16 bit home computer programming techniques, after all these years, mostly I guess caused by the scripting languages for everything during the last two decades.

markus0today at 7:00 PM

I want to work more with systems that always abide by such strict constraints and style / design guides, but at the same time I feel like the reality of building software at scale is teams ending up working in subsystems that don’t consider the holistic operating model of the program. So even with best practices locally, the system as a whole ends up fragmented and inefficient, and strict global constraints therefore feel limiting.

theokruegertoday at 6:12 PM

static allocation is de-facto standard in embedded for obvious reasons, and works really well there. in operating systems with more complex memory models designed entirely around dynamic workloads, im not sure asking devs to adopt another slightly complicated design pattern that imposes new hard caps is any less of a cognitive load than before.

i can't bash the functionality and correctness aspect of static allocation, but it is akin to the humble linked list in the sense that you should already know going into the problem that you need it.

show 1 reply