Jump to content

Object Pooling


Recommended Posts

So, as far as I can tell, the typical way to do an object pool is to create a bunch of objects ahead of time, and reuse them throughout the rest of the game, reviving dead ones as needed. Of course, this means that enough objects need to be made ahead of time so that when a new one is needed, there is a dead one to be revived.

 

I've done a pool before where I will revive if there is a dead object, and make a new one if not. Perhaps its my laziness kicking in here, because I don't really want to estimate at how many objects I will need in a particular game.

 

I can see some drawbacks in extra code in an update function that looks odd, and also the impact on gameplay of making a new object at runtime. Should I be sticking with only the prefilled pools, or is the 'elastic' approach acceptable too?

Link to comment
Share on other sites

A poolmanager should be able to create objects when required as this is less error prone. I usually do some pre-fills depending on the game, usually when I'm concerned about lag during the main loop. Object creation is pretty fast though so for most games this is probably not needed.

Link to comment
Share on other sites

I once shot myself in the foot with object pooling, as the HaXe GC was constantly firing on my allocated pool nodes as it couldn't understand those shouldn't be considered for GC and constantly traversed them :( (That's for C++ target, as HaXe doesn't have own gc for JavaScript, but the point remains the same - double check if you really need it!)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...