Jump to content
  • Advertisement
Sign in to follow this  

C++: small object allocator and object hierarchies

This topic is 3436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I think I'd like a good way to build a small object allocator that handles generic objects (presumably in a hierarchy). On the one end, for something like a particle system, you have many small objects constantly being created and destroyed. They're basically all the same so you make some struct/class particle with some reasonable set of member variables like position, texture, etc. The SOA then creates some big array and you access it to create and delete new particles. In some sense all your objects are just data and they're all uniform so implementing an SOA is obvious. At the opposite end of the spectrum you have an object hierarchy, for example, Object, ObjectPlayer, ObjectBullet, ObjectPowerup, ObjectMonsterA, ObjectMonsterB, etc, with maybe a virtual update() function and different member variables depending on the objects. Clearly this object system has some properties that mesh well with an SOA system, namely relatively small objects that get constantly created and deleted. The trouble is the objects are no longer uniform in size and they aren't just data anymore, they have code associated with them as well. This makes implementing an SOA non-trivial. I can see many solutions. Forget about SOAs, use new and delete and just store pointers. Forget about an object hierarchy and just store data. Force the objects into a uniform mold and use pointers to functions and/or lots of type-casting. Create an SOA for each object type. All of the above are either awkward or result in lots of new/delete memory fragmentation.

Share this post


Link to post
Share on other sites
Advertisement
Sweet. Just doing a search on 'pools' helped a lot. I had the right idea, but the details required to get proper object construction, virtual functions, and destructors to work weren't obvious.

Thank you sir.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!