libgdx API

com.badlogic.gdx.utils
Class Pool<T>

java.lang.Object
  extended by com.badlogic.gdx.utils.Pool<T>
Direct Known Subclasses:
ActionResetingPool, ParticleEffectPool

public abstract class Pool<T>
extends java.lang.Object

A pool of objects that can be resused to avoid allocation.

Author:
Nathan Sweet

Field Summary
 int max
           
 
Constructor Summary
Pool()
          Creates a pool with an initial capacity of 16 and no maximum.
Pool(int initialCapacity)
          Creates a pool with the specified initial capacity and no maximum.
Pool(int initialCapacity, int max)
           
 
Method Summary
 void clear()
          Removes all free objects from this pool.
 void free(Array<T> objects)
          Puts the specified objects in the pool.
 void free(T object)
          Puts the specified object in the pool, making it eligible to be returned by obtain().
protected abstract  T newObject()
           
 T obtain()
          Returns an object from this pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

max

public final int max
Constructor Detail

Pool

public Pool()
Creates a pool with an initial capacity of 16 and no maximum.


Pool

public Pool(int initialCapacity)
Creates a pool with the specified initial capacity and no maximum.


Pool

public Pool(int initialCapacity,
            int max)
Parameters:
max - The maximum number of free objects to store in this pool.
Method Detail

newObject

protected abstract T newObject()

obtain

public T obtain()
Returns an object from this pool. The object may be new (from newObject()) or reused (previously freed).


free

public void free(T object)
Puts the specified object in the pool, making it eligible to be returned by obtain(). If the pool already contains max free objects, the specified object is ignored.


free

public void free(Array<T> objects)
Puts the specified objects in the pool.

See Also:
free(Object)

clear

public void clear()
Removes all free objects from this pool.


libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)