3 ms·
My recommendation is that you do whatever you feel like with ownership when you first write the code, but then if something forces you to come back and change h
by oconnor663 2y ago
My recommendation is that you do whatever you feel like with ownership when you first write the code, but then if something forces you to come back and change how ownership works, seriously consider switching to https://jacko.io/object_soup.html https://jacko.io/object_soup.html.
- amelius 2y agoIsn'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.