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

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

public abstract class Pool<T>
extends Object

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

Author:
Nathan Sweet

Nested Class Summary
static interface Pool.Poolable
          Objects implementing this interface will have Pool.Poolable.reset() called when passed to free(Object).
 
Field Summary
 int max
          The maximum number of objects that will be pooled.
 int peak
          The highest number of free objects.
 
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(T object)
          Puts the specified object in the pool, making it eligible to be returned by obtain().
 void freeAll(Array<T> objects)
          Puts the specified objects in the pool.
 int getFree()
          The number of objects available to be obtained.
 T obtain()
          Returns an object from this pool.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

max

public final int max
The maximum number of objects that will be pooled.


peak

public int peak
The highest number of free objects. Can be reset any time.

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

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 reset but not added to the pool.


freeAll

public void freeAll(Array<T> objects)
Puts the specified objects in the pool. Null objects within the array are silently ignored.

See Also:
free(Object)

clear

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


getFree

public int getFree()
The number of objects available to be obtained.



Copyright © 2014. All Rights Reserved.