public class FloatArrayFactory extends Object
Creating arrays in a heavy, fast-paced loop ends up being very expensive. This stores arrays and returns them on demand.
This factory stores these arrays with strong references, so this class should only really be used when the possible array sizes are limited and the usage is predictable.
| Constructor and Description |
|---|
FloatArrayFactory()
|
| Modifier and Type | Method and Description |
|---|---|
float[] |
getArray(int size)
Returns a float array of the indicated size.
|
static FloatArrayFactory |
getStaticFactory()
|
void |
putArray(float[] array)
Stores an array for future use.
|
public static FloatArrayFactorygetStaticFactory()
public float[] getArray(int size)
If arrays of that size have previously been stored in this factory, then an existing array will be returned.
size - the array size you need.
public void putArray(float[] array)
As soon as you call this method you should nullify all other references to the argument. If you continue to use it, and someone else retrieves this array by calling getArray(), then you may have two entities using the same array to manipulate data... and that can be really hard to debug!
array - the array you no longer need that might be needed later.