public abstract class Pool<T> extends Object
Pools
Modifier and Type | Class and Description |
---|---|
static interface |
Pool.Poolable
Objects implementing this interface will have
Pool.Poolable.reset() called when passed to free(Object) . |
Modifier and Type | Field and Description |
---|---|
int |
max
The maximum number of objects that will be pooled.
|
int |
peak
The highest number of free objects.
|
Constructor and Description |
---|
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) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes and discards all free objects from this pool.
|
void |
fill(int size)
Adds the specified number of new free objects to the 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.
|
public final int max
public int peak
public Pool()
public Pool(int initialCapacity)
public Pool(int initialCapacity, int max)
initialCapacity
- The initial size of the array supporting the pool. No objects are created/pre-allocated. Use
fill(int)
after instantiation if needed.max
- The maximum number of free objects to store in this pool.public T obtain()
newObject()
) or reused (previously
freed
).public void free(T object)
obtain()
. If the pool already contains
max
free objects, the specified object is discarded
and 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.
public void fill(int size)
size
- the number of objects to be addedpublic void freeAll(Array<T> objects)
The pool does not check if an object is already freed, so the same object must not be freed multiple times.
free(Object)
public void clear()
public int getFree()
Copyright © 2021. All rights reserved.