Package de.gsi.dataset.utils
Class DoubleArrayCache
- java.lang.Object
-
- java.util.AbstractCollection<T>
-
- de.gsi.dataset.utils.CacheCollection<double[]>
-
- de.gsi.dataset.utils.DoubleArrayCache
-
- All Implemented Interfaces:
java.lang.Iterable<double[]>,java.util.Collection<double[]>
public class DoubleArrayCache extends CacheCollection<double[]>
Implements double-array (double[]) cache collection to minimise memory re-allocation.N.B. This is useful to re-use short-lived data storage container to minimise the amount of garbage to be collected. This is used in situation replacing e.g.
withpublic returnValue frequentlyExecutedFunction(...) { final double[] storage = new byte[10000]; // allocate new memory block (costly) // [...] do short-lived computation on storage // storage is implicitly finalised by garbage collector (costly) }// ... private final ByteArrayCache cache = new ByteArrayCache(); // ... public returnValue frequentlyExecutedFunction(...) { final double[] storage = cache.getArray(10000); // return previously allocated array (cheap) or allocated new if necessary // [...] do short-lived computation on storage cache.add(storage); // return object to cache }- Author:
- rstein
-
-
Field Summary
-
Fields inherited from class de.gsi.dataset.utils.CacheCollection
contents
-
-
Constructor Summary
Constructors Constructor Description DoubleArrayCache()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double[]getArray(int requiredSize)double[]getArrayExact(int requiredSize)static DoubleArrayCachegetInstance()-
Methods inherited from class de.gsi.dataset.utils.CacheCollection
add, cleanup, clear, contains, iterator, remove, size
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
getArray
public double[] getArray(int requiredSize)
-
getArrayExact
public double[] getArrayExact(int requiredSize)
-
getInstance
public static DoubleArrayCache getInstance()
-
-