public class DoubleArrayCache extends CacheCollection<double[]>
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.
public 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)
}
with
// ...
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
}
contents| Constructor and Description |
|---|
DoubleArrayCache() |
| Modifier and Type | Method and Description |
|---|---|
double[] |
getArray(int requiredSize) |
double[] |
getArrayExact(int requiredSize) |
static DoubleArrayCache |
getInstance() |
add, cleanup, clear, contains, iterator, remove, sizeaddAll, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitequals, hashCode, parallelStream, removeIf, spliterator, streampublic double[] getArray(int requiredSize)
public double[] getArrayExact(int requiredSize)
public static DoubleArrayCache getInstance()
Copyright © 2020 GSI Helmholtzzentrum für Schwerionenforschung GmbH. All rights reserved.