Reusable Java library of general tools with minimal external dependencies.
For questions or support, please contact us:
Email: support@aoindustries.com
Phone: 1-800-519-9541
Phone: +1-251-607-9556
Web: https://www.aoindustries.com/contact
public final class BufferManager extends Object
BufferManager manages a reusable pool of byte[] and char[] buffers.
This avoids the repetitive allocation of memory for an operation that only needs a temporary buffer.
The buffers are stored as ThreadLocal to maximize cache locality.
Do not use if intra-thread security is more important than performance.
The buffers are not necessarily 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.
Buffers must not be passed between threads, as each thread has an unlimited number of possible buffers. Giving a thread a buffer you didn't get from it could result in a memory leak.
TODO: Implement as concurrent queue/deque instead of thread locals?| 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 © 2000–2016 AO Industries, Inc.. All rights reserved.