0
\$\begingroup\$

According to When and why is a Pool class needed to hold objects?, pools are used when the number of "instances" of an object fluctuates. However, StarWarrior (the Artemis example) uses a pool for the player (of which there is always only one) and no pool for the enemies (which fluctuate and which more exist).

So what is the deal with pools?

Specifically:

  • What are pools?
  • Why are pools?
  • Where are pools?
  • What is the difference between AddComponentFromPool and AddComponent (from
    Artemis)?
  • What is the difference between extending IComponent and ComponentPoolable (from Artemis)?
\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

Pools are like a recycle been for objects. They are used to avoid unneeded memory management (free and malloc in c, new and delete in c++ ... garbage collection activity in Java and AS3 and so forth).

You basically use a container to store objects (or in c / c++ pointers to objects) that are currently not in use but might be needed soon.

For instance, instead of firing the CTOR (constructor) to create a new enemy instance, only to fire the DTOR (destructor) to deallocate resources once it's dead; you put a bunch of enemies in advance inside a container called a pool. When they are needed, you remove some from the pool and when they are no longer needed (dead or just suspended) you put them back in the pool. Later you can start resetting the appropriate values and reuse these objects.

From what I could tell, the 'AddComponentFromPool' is used when the component inherits from 'ComponentPoolable' which basically means that is relying on pools to help with memory management.

\$\endgroup\$
1
  • \$\begingroup\$ Here is a great link \$\endgroup\$ Commented Mar 14, 2014 at 19:49

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.