In Starcraft, you construct a base, manage an economy, and train military units to tear down the other opponent until either all their buildings are gone, or until they leave. Each unit you train has a designated "food usage", meaning that you may create a unit until you run out of "supply", or your food count is lower than the required food usage. To manage this, you create supply buildings (or in zerg's case, Overlords) to increase your supply. However, you may only have a maximum of 200 food. This is called an object pool.
|In Starcraft, you may use a maximum of 200 food. When a unit dies, it no longer uses that food.|
You can think of the object pool as an array. You have this array of 10 circles as such:
Circle circles = new Circle;
Now, say you want to use 3 spots in the array to create 3 circles, so you would type:
for(int x = 0; x < 3; x++)
circles[x] = new Circle(3.4f); // 3.4f would be the "radius" in this case
Now say you wanted more than three, you would simply designate which "empty circle" you want to use to contruct a new one.
circle = new circle(4.2f);
But what if you want to "destroy" one of these circles? Well, when using pools, you don't actually "destroy" an object. You simply just change its properties to make it what you call empty.
circle.radius = 0;
Or you can create a boolean variable "IsActive" to let the program know if it is active or not.
circle.IsActive = false;
When you have a property like this, you can make a constantly running function that runs through all the objects (circles, in this case), check if it is active, if not, do not use (in video game design, you can tell the engine not to render the "circles" that are inactive)
for(int x = 0; x < circles.length; x++
circles[x].Draw(); //If the circle IS active, then the engine will draw it on the screen
The reason why "pooling" is standard practice is because it is an efficient way to handle multiple objects. Why would you want your game to constantly create hundreds, even thousands of objects, and then just get rid of the memory? Why not just re-use those objects? If you have any questions about pooling, please post in the comments.