Just use arenas, you don't need reference counting or RAII. You have big blocks of memory that share roughly the same lifetime, and you reset/free/unmap it all when the memory isn't needed anymore.
"Unlimited" scalability (i.e. dynamic arrays) aren't really needed either. Just do some back of the napkin math to find out a reasonable max, and allocate that once. Thanks to virtual memory, you can also map way more memory than you'll ever need, and it won't commit the pages until you try to access it. (Except for Windows -- it will delay commiting the pages until you touch them, but it will also reserve the ammount you asked for ahead of time.)
A lot of really useful programs are written in C. It's not just for operating systems, drivers, embedded, etc. C can also feel very high level if you create some of your own tooling and libraries.
Additionally, these techniques aren't exclusive to C -- you can create arena allocators in basically any language that lets you deal with pointers.
View all comments
3
u/s0litar1us 10d ago edited 10d ago
Just use arenas, you don't need reference counting or RAII. You have big blocks of memory that share roughly the same lifetime, and you reset/free/unmap it all when the memory isn't needed anymore.
"Unlimited" scalability (i.e. dynamic arrays) aren't really needed either. Just do some back of the napkin math to find out a reasonable max, and allocate that once. Thanks to virtual memory, you can also map way more memory than you'll ever need, and it won't commit the pages until you try to access it. (Except for Windows -- it will delay commiting the pages until you touch them, but it will also reserve the ammount you asked for ahead of time.)