3 ms·
Isn't that just reinventing the heap, but with indexes in a vector instead of with addresses in memory?
by amelius 2y ago
Isn't that just reinventing the heap, but with indexes in a vector instead of with addresses in memory?
- oconnor663 2y agoYou could look at it that way. But C++ programs often use similar strategies, even though they don't have to. Array/Vec based layouts like this give you the option of doing some very fancy high-performance stuff, and they also happen to play nicely with the borrow checker.
- amelius 2y agoIt's very basic and not a general solution because the lifetimes of objects are now set equal. And there's no compaction, so from a space perspective it is worse than a heap where the space of deleted objects can be filled up by new objects. It is nice though that you can delete an entire class of objects in one operation. I have used this type of memory management in the context of web requests, where the space could be freed when the request was done.