Package arc.util.pooling
Class Pool<T>
java.lang.Object
arc.util.pooling.Pool<T>
A pool of objects that can be reused to avoid allocation.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Objects implementing this interface will havePool.Poolable.reset()
called when passed tofree(Object)
. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all free objects from this pool.void
Puts the specified object in the pool, making it eligible to be returned byobtain()
.void
Puts the specified objects in the pool.int
getFree()
The number of objects available to be obtained.protected abstract T
obtain()
Returns an object from this pool.protected void
Called when an object is freed to clear the state of the object for possible later reuse.
-
Field Details
-
max
public final int maxThe maximum number of objects that will be pooled. -
peak
public int peakThe highest number of free objects. Can be reset any time.
-
-
Constructor Details
-
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 Details
-
newObject
-
obtain
Returns an object from this pool. The object may be new (fromnewObject()
) or reused (previouslyfreed
). -
free
-
reset
Called when an object is freed to clear the state of the object for possible later reuse. The default implementation callsPool.Poolable.reset()
if the object isPool.Poolable
. -
freeAll
Puts the specified objects in the pool. Null objects within the array are silently ignored.The pool does not check if an object is already freed, so the same object must not be freed multiple times.
- See Also:
-
clear
public void clear()Removes all free objects from this pool. -
getFree
public int getFree()The number of objects available to be obtained.
-