public final class BufferManager extends Object
BufferManager manages a reusable pool of byte[] and char[]
buffers. The buffers are stored as ThreadLocal to avoid overhead in NUMA architectures.
This avoids the repetitive allocation of memory for an operation that only needs a temporary buffer.
The buffers are not cleared between invocations so the results of previous operations may be available
to additional callers. On the scale of security versus performance, this is biased toward performance.
However, being thread local there remains some control over the visibility of the data.
Do not use if intra-thread security is more important than performance.| Modifier and Type | Field and Description |
|---|---|
static int |
BUFFER_SIZE
The size of buffers that are returned.
|
| Modifier and Type | Method and Description |
|---|---|
static long |
getByteBufferCreates() |
static long |
getByteBufferUses() |
static byte[] |
getBytes()
Gets a
byte[] of length BUFFER_SIZE that may
be temporarily used for any purpose. |
static long |
getCharBufferCreates() |
static long |
getCharBufferUses() |
static char[] |
getChars()
Gets a
char[] of length BUFFER_SIZE that may
be temporarily used for any purpose. |
static void |
release(byte[] buffer)
Deprecated.
May obtain greater performance by avoiding zero fill on non-sensitive data.
|
static void |
release(byte[] buffer,
boolean zeroFill)
Releases a
byte[] that was obtained by a call to
getBytes. |
static void |
release(char[] buffer)
Deprecated.
May obtain greater performance by avoiding zero fill on non-sensitive data.
|
static void |
release(char[] buffer,
boolean zeroFill)
Releases a
char[] that was obtained by a call to
getChars. |
public static final int BUFFER_SIZE
public static byte[] getBytes()
byte[] of length BUFFER_SIZE that may
be temporarily used for any purpose. Once done with the buffer,
releaseBuffer should be called, this is best accomplished
in a finally block.
The buffer is not necessarily zero-filled and may contain data from a previous use.public static char[] getChars()
char[] of length BUFFER_SIZE that may
be temporarily used for any purpose. Once done with the buffer,
releaseBuffer should be called, this is best accomplished
in a finally block.
The buffer is not necessarily zero-filled and may contain data from a previous use.@Deprecated public static void release(byte[] buffer)
public static void release(byte[] buffer,
boolean zeroFill)
byte[] that was obtained by a call to
getBytes.buffer - the byte[] to releasezeroFill - if the data in the buffer may be sensitive, it is best to zero-fill the buffer on release.@Deprecated public static void release(char[] buffer)
public static void release(char[] buffer,
boolean zeroFill)
char[] that was obtained by a call to
getChars.buffer - the char[] to releasezeroFill - if the data in the buffer may be sensitive, it is best to zero-fill the buffer on release.public static long getByteBufferCreates()
public static long getByteBufferUses()
public static long getCharBufferCreates()
public static long getCharBufferUses()
Copyright © 2016. All rights reserved.