Class FloatArrayFactory



  • public class FloatArrayFactory
    extends Object
    This is a mechanism to recycle arrays.

    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 Detail

      • FloatArrayFactory

        public FloatArrayFactory()
    • Method Detail

      • getArray

        public float[] getArray(int size)
        Returns a float array of the indicated size.

        If arrays of that size have previously been stored in this factory, then an existing array will be returned.

        Parameters:
        size - the array size you need.
        Returns:
        a float array of the size indicated.
      • putArray

        public void putArray(float[] array)
        Stores an array for future use.

        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!

        Parameters:
        array - the array you no longer need that might be needed later.