News for hackers. Stuff that matters.
Re:Ask HN: Why is there not a memory-safe C? by pjc50 on Thursday May 24, 2018 @08:51AM (#17143431)
There's also the "embedded" style: no memory allocation. Throw away malloc() from your standard library and make all variables static globals. It looks odd and all sorts of things become unreasonably hard (such as networking and text processing), but it does guarantee you don't get heap-related bugs if you don't have a heap.
Re:Ask HN: Why is there not a memory-safe C? by gravypod on Thursday May 24, 2018 @08:59AM (#17143502)
Back in the olden times game development studios used to do this. They would pre-estimate the maximum number of everything happening (explosion, ai, ammo, etc) and pre allocate everything. Then allocation and deallocations is just a fifo of spaced pointers built on a block of memory pre laid out in a structure in the binary.

If you allocate 2x the memory you need then there's no risk of overflows. It's riskier but it makes all of the code dead simple, extremely fast, and is a good middleground between embedded and normal.

You do get large binaries though...

Re:Ask HN: Why is there not a memory-safe C? by pjc50 on Thursday May 24, 2018 @09:09AM (#17143579)
Yes, and if it's zero-initialised it can take up zero space in the binary.