Class Pool<T>
java.lang.Object
arc.util.pooling.Pool<T>
com.xpdustry.claj.common.util.Pool<T>
public class Pool<T>
extends arc.util.pooling.Pool<T>
Taken from arc-lite.
A pool of objects that can be reused to avoid allocation. The implementation is thread-safe, lock-less, and pool array is preallocated.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class arc.util.pooling.Pool
arc.util.pooling.Pool.Poolable -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal intThe maximum number of objects that can be pooled.intThe highest number of free objects.Fields inherited from class arc.util.pooling.Pool
max -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all free objects from this pool.voidfill()Fill the pool with new objects.voidfill(int size) Fill the pool withsizenew objects.voidPuts the specified object in the pool, making it eligible to be returned byobtain().voidPuts the specified objects in the pool.intgetFree()The number of objects available to be obtained.protected Tobtain()Returns an object from this pool.booleanSame as, but returnsinvalid reference
#free()trueif the object has been placed to the pool array.poll()Same asobtain(), but returnsnullinstead of allocating a new object if the pool is empty.protected voidCalled when an object is freed to clear the state of the object for possible later reuse.
-
Field Details
-
capacity
public final int capacityThe maximum number of objects that can be pooled. -
peak
public volatile int peakThe highest number of free objects. Can be reset any time.
-
-
Constructor Details
-
Pool
Creates a pool with a maximum capacity of2048objects. -
Pool
- Parameters:
capacity- 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).- Overrides:
obtainin classarc.util.pooling.Pool<T>
-
poll
-
free
Puts the specified object in the pool, making it eligible to be returned byobtain(). If the pool already containsPool.maxfree objects, the specified object is reset but not added to the pool.The pool does not check if an object is already freed, so the same object must not be freed multiple times.
- Overrides:
freein classarc.util.pooling.Pool<T>
-
offer
Same as, but returnsinvalid reference
#free()trueif the object has been placed to the pool array. Else it means that the pool is full. -
reset
-
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.
- Overrides:
freeAllin classarc.util.pooling.Pool<T>- See Also:
-
fill
public void fill()Fill the pool with new objects. -
fill
public void fill(int size) Fill the pool withsizenew objects. -
clear
public void clear()Removes all free objects from this pool.- Overrides:
clearin classarc.util.pooling.Pool<T>
-
getFree
public int getFree()The number of objects available to be obtained. This can be an estimation if pool is highly used.- Overrides:
getFreein classarc.util.pooling.Pool<T>
-