Private Tag Reporter
kiwifarms.net
- Joined
- Jul 7, 2024
Perfect, trashing the heap on scope exit is what I'm looking for.There's nothing stopping you from rolling your own "RAII malloc" though, you can set up an arena allocator (or equivalent) in your local scope, and trash it on scope exit.
Windows will actually let you easily create your own private heap that works the same way as "the" CRT malloc. Not sure about Linux.
No worries, appreciate your insight as well. I think I worded the question pretty poorly, since it was less language specific to C and more a question of languages/compilers in general. Alloca() - and its associated limitations - is kind of the naive implementation of what I'm thinking about, memory that expires when its stack frame ends.I can't really make sense of your smart pointer scheme, but afaict it has no way to detect when lifetimes end (so it can't replace refcounting) and it also sounds like it'd have overhead on every access, which is a lot. For comparison, refcounting only has overhead on assignment and tracing GCs typically have small overhead during assignment and large infrequent overhead on allocation.
Sorry if I'm retreading basics here, but just from your post it's not really clear what level you're at.
I'm thinking about ownership and automatic memory management without garbage collection, and what the potential pitfalls might be. To be honest, I think I'm in over my head. The answer seems both obvious (the memory is no longer needed when the system closes), and obscure (how to determine a system is closed).
While doing some looking into this I found a whitepaper for something called Perceus and a language called Koka; Perceus appears to be ref-counting without garbage collection, which is what I'm interested in, so my initial feeling is that I'm going to have to do some more reading up before going anywhere with this idea.