Package org.apache.parquet.bytes
Class ReusingByteBufferAllocator
java.lang.Object
org.apache.parquet.bytes.ReusingByteBufferAllocator
- All Implemented Interfaces:
AutoCloseable,ByteBufferAllocator
public abstract class ReusingByteBufferAllocator
extends Object
implements ByteBufferAllocator, AutoCloseable
A special
ByteBufferAllocator implementation that keeps one ByteBuffer object and reuses it at the
next allocate(int) call. The close() shall be called when this allocator is not needed anymore to
really release the one buffer.-
Method Summary
Modifier and TypeMethodDescriptionallocate(int size) voidclose()A convenience method to get aByteBufferReleaserinstance already created for this allocator.booleanisDirect()Indicates if this allocator will produce ByteBuffers backed by direct memory.voidFor RefCounted implementations using direct memory, the release method needs to be called to free references to the allocated memory.static ReusingByteBufferAllocatorstrict(ByteBufferAllocator allocator) Creates a new strictReusingByteBufferAllocatorobject with the specified "parent" allocator to be used for allocating/releasing the one buffer.static ReusingByteBufferAllocatorunsafe(ByteBufferAllocator allocator) Creates a new unsafeReusingByteBufferAllocatorobject with the specified "parent" allocator to be used for allocating/releasing the one buffer.
-
Method Details
-
strict
Creates a new strictReusingByteBufferAllocatorobject with the specified "parent" allocator to be used for allocating/releasing the one buffer.Strict means it is enforced that
release(ByteBuffer)is invoked before a newallocate(int)can be called.- Parameters:
allocator- the allocator to be used for allocating/releasing the one buffer- Returns:
- a new strict
ReusingByteBufferAllocatorobject
-
unsafe
Creates a new unsafeReusingByteBufferAllocatorobject with the specified "parent" allocator to be used for allocating/releasing the one buffer.Unsafe means it is not enforced that
release(ByteBuffer)is invoked before a newallocate(int)can be called, i.e. no exceptions will be thrown atallocate(int).- Parameters:
allocator- the allocator to be used for allocating/releasing the one buffer- Returns:
- a new unsafe
ReusingByteBufferAllocatorobject
-
getReleaser
A convenience method to get aByteBufferReleaserinstance already created for this allocator.- Returns:
- a releaser for this allocator
-
allocate
- Specified by:
allocatein interfaceByteBufferAllocator- Throws:
IllegalStateException- if strict and the one buffer was not released yet- See Also:
-
release
For RefCounted implementations using direct memory, the release method needs to be called to free references to the allocated memory.- Specified by:
releasein interfaceByteBufferAllocator- Parameters:
b- a ByteBuffer- Throws:
IllegalStateException- if the one buffer has already been released or never allocatedIllegalArgumentException- if the specified buffer is not the one allocated by this allocator
-
isDirect
public boolean isDirect()Description copied from interface:ByteBufferAllocatorIndicates if this allocator will produce ByteBuffers backed by direct memory.- Specified by:
isDirectin interfaceByteBufferAllocator- Returns:
- true if direct memory backed buffers will be created by this allocator, else false
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-