|
Sea 0.4.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object gov.lbl.dsd.sea.nio.util.ByteArrayPool
Simple fixed-size thread-safe pool for recycling byte arrays. Each thread has its own local pool, and each pool can hold at most a given number of byte arrays, evicting arrays beyond that point, as configured through a system property.
Completely unsynchronized, yet thread-safe implementation.
Simple, but often effective if an application creates medium to large temporary arrays at very high frequency, as is often the case in safe and clean I/O buffer management for network servers.
This is not a general purpose replacement for Javas built-in memory and garbage collection subsystem! Do not abuse this class for small or infrequent arrays - those are handled better (read: near-optimal) by the generational garbage collectors and memory allocators of current VMs.
Method Summary | |
static void |
put(byte[] bytes)
Recycles the given byte array back to the pool. |
static byte[] |
take(int minSize)
Returns a byte array that has at least the given size. |
static byte[] |
takeExactly(int size)
Returns a byte array that has exactly the given size. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static byte[] takeExactly(int size)
size
- the desired size of the byte array.
public static byte[] take(int minSize)
minSize
- the minimum desired size of the byte array.
public static void put(byte[] bytes)
bytes
- the array to recycle
|
Sea 0.4.0 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |