Class ZeroBytePool
java.lang.Object
de.tomatengames.util.pool.ZeroBytePool
- All Implemented Interfaces:
BytePool
A BytePool wrapper that clears (zeros) the provided byte arrays on free.
If this is the only access to the underlying BytePool, then all unused byte arrays are clear and are clear when claimed.
This may wrap other BytePools to improve
- Data protection: Caller data does not remain in memory of the pool but instead gets immediately deleted when no longer used.
- Fail-safety: Caller data written to and left in the byte array is never given to other callers. Callers should never use the contents of their claimed byte arrays without overwriting them first, but that may happen through bugs in caller code. Clearing the contents can drastically lower the severity of such a bug because it is just zeros then.
- Since:
- 1.8
-
Constructor Summary
ConstructorsConstructorDescriptionZeroBytePool(BytePool source) Constructs a new ZeroBytePool that wraps the specified source BytePool. -
Method Summary
Modifier and TypeMethodDescriptionPooled<byte[]> claim(int minLength) Claims a byte array that is at least as long as the specified minimum length.static voidzero(byte[] array) Clears all elements in the specified byte array by setting them to zero.static voidzero(byte[] array, int off, int len) Clears the specified range in the specified byte array by setting its elements in that range to zero.
-
Constructor Details
-
ZeroBytePool
Constructs a new ZeroBytePool that wraps the specified source BytePool.- Parameters:
source- the underlying BytePool to wrap
-
-
Method Details
-
zero
public static void zero(byte[] array) Clears all elements in the specified byte array by setting them to zero.- Parameters:
array- the byte array to be zeroed out
-
zero
public static void zero(byte[] array, int off, int len) Clears the specified range in the specified byte array by setting its elements in that range to zero.- Parameters:
array- the byte array to be zeroed outoff- the starting index within the array where zeroing beginslen- the number of bytes to set to zero
-
claim
Description copied from interface:BytePoolClaims a byte array that is at least as long as the specified minimum length.
-