Object pooling example?

Hi

I’m just starting to play around with Defold. I’ve decided to recreate my iOS game Galaxoid as an excercise so that I can learn how things work. One thing that I’ve not been to able to find any information on is how one would implement object pooling in Defold. Could some point me to an example of how you would this in Defold?

Thanks!
Jacob

EDIT In Defod, there is no need for object pools for perf reasons. The advice below is meant for when you for some reason want to have an object pool for your particular game design. There is more info on the perf side in this other thread.
EDIT2 If you do want to have a large number of lua objects (tables, vectors, etc) alive, it might in some cases be wise to put them in an object pool for perf reasons. But it does not apply to game objects, which are very cheap to create/destroy.

I’m not sure I know what you mean by object pooling, so I assume you mean keeping a bunch of objects that can be acquired/released? You can use the lua datastructures for that, e.g. the table. Probably plenty of examples on the web. From the top of my head, I would suggest you use two tables, one for free and one for acquired objects. If you want to put game object instances in it, you can index the tables by the id of the game objects and then you just need to move them between the tables.

1 Like

@Ragnar_Svensson you are correct. Im referring to the practice of instantiating a set number of objects, keeping them in an array (table for lua I assume). Then instead of creating a bunch of garbage for the garbage collector to deal with by instantiating and deleting objects, they can be reused if not in use. I’ll give a try to your suggestion.

Thanks!
Jacob

1 Like

Cool, yes that should work fine!

1 Like

Maybe, we have to suggest this feature to engine devs? It can be a Factory feature “create objects pool” it can increase apps performance greatly.

2 Likes

Would be great to have object pool into engine with simple implementation.
I think, many developers will agree that object pool is “must have” in all game engines today.
And as @Sublustris told, it can be option in factory component, because factory now looks like useless component.

2 Likes

I replied to this in the other thread: Objects pooling for Factories (SOLVED)
I should probably have kept the discussion in this one… :confused:

2 Likes