Class BasicArrayCache
ArrayCache implementation.
This caches exact array sizes, that is, getByteArray will return
an array whose size is exactly the requested size. A limited number
of different array sizes are cached at the same time; least recently used
sizes will be dropped from the cache if needed (can happen if several
different (de)compression options are used with the same cache).
The current implementation uses
LinkedHashMap to map different array sizes
to separate array-based data structures which hold
SoftReferences to the cached arrays.
In the common case this should give good performance and fairly low
memory usage overhead.
A statically allocated global BasicArrayCache instance is
available via getInstance() which is a good choice in most
situations where caching is wanted.
- Since:
- 1.7
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]getByteArray(int size, boolean fillWithZeros) Allocates a new byte array, hopefully reusing an existing array from the cache.static BasicArrayCacheReturns a statically-allocatedBasicArrayCacheinstance.int[]getIntArray(int size, boolean fillWithZeros) This is like getByteArray but for int arrays.voidputArray(byte[] array) Puts the given byte array to the cache.voidputArray(int[] array) Puts the given int array to the cache.Methods inherited from class org.graalvm.shadowed.org.tukaani.xz.ArrayCache
getDefaultCache, getDummyCache, setDefaultCache
-
Constructor Details
-
BasicArrayCache
public BasicArrayCache()
-
-
Method Details
-
getInstance
Returns a statically-allocatedBasicArrayCacheinstance. This is often a good choice when a cache is needed. -
getByteArray
public byte[] getByteArray(int size, boolean fillWithZeros) Allocates a new byte array, hopefully reusing an existing array from the cache.- Overrides:
getByteArrayin classArrayCache- Parameters:
size- size of the array to allocatefillWithZeros- if true, all the elements of the returned array will be zero; if false, the contents of the returned array is undefined
-
putArray
public void putArray(byte[] array) Puts the given byte array to the cache. The caller must no longer use the array.Small arrays aren't cached and will be ignored by this method.
- Overrides:
putArrayin classArrayCache
-
getIntArray
public int[] getIntArray(int size, boolean fillWithZeros) This is like getByteArray but for int arrays.- Overrides:
getIntArrayin classArrayCache- Parameters:
size- the minimum size of the array to allocate; an implementation may return an array that is larger than the givensizefillWithZeros- if true, the caller expects that the firstsizeelements in the array are zero; if false, the array contents can be anything, which speeds things up when reusing a cached array
-
putArray
public void putArray(int[] array) Puts the given int array to the cache. The caller must no longer use the array.Small arrays aren't cached and will be ignored by this method.
- Overrides:
putArrayin classArrayCache
-