public interface BufferAllocator extends AutoCloseable
Modifier and Type | Method and Description |
---|---|
void |
assertOpen()
Asserts (using java assertions) that the provided allocator is currently open.
|
ArrowBuf |
buffer(long size)
Allocate a new or reused buffer of the provided size.
|
ArrowBuf |
buffer(long size,
BufferManager manager)
Allocate a new or reused buffer of the provided size.
|
void |
close()
Close and release all buffers generated from this buffer pool.
|
boolean |
forceAllocate(long size)
Forcibly allocate bytes.
|
long |
getAllocatedMemory()
Returns the amount of memory currently allocated from this allocator.
|
Collection<BufferAllocator> |
getChildAllocators()
Returns the set of child allocators.
|
ArrowBuf |
getEmpty()
Get a reference to the empty buffer associated with this allocator.
|
long |
getHeadroom()
Returns the amount of memory that can probably be allocated at this moment
without exceeding this or any parents allocation maximum.
|
long |
getInitReservation()
Return the initial reservation.
|
long |
getLimit()
Return the current maximum limit this allocator imposes.
|
AllocationListener |
getListener()
Returns the allocation listener used by this allocator.
|
String |
getName()
Return the name of this allocator.
|
BufferAllocator |
getParentAllocator()
Returns the parent allocator.
|
long |
getPeakMemoryAllocation()
Returns the peak amount of memory allocated from this allocator.
|
BufferAllocator |
getRoot()
Get the root allocator of this allocator.
|
default RoundingPolicy |
getRoundingPolicy()
Gets the rounding policy of the allocator.
|
boolean |
isOverLimit()
Return whether or not this allocator (or one if its parents) is over its limits.
|
BufferAllocator |
newChildAllocator(String name,
AllocationListener listener,
long initReservation,
long maxAllocation)
Create a new child allocator.
|
BufferAllocator |
newChildAllocator(String name,
long initReservation,
long maxAllocation)
Create a new child allocator.
|
AllocationReservation |
newReservation()
Create an allocation reservation.
|
void |
releaseBytes(long size)
Release bytes from this allocator.
|
void |
setLimit(long newLimit)
Set the maximum amount of memory this allocator is allowed to allocate.
|
String |
toVerboseString()
Return a verbose string describing this allocator.
|
default ArrowBuf |
wrapForeignAllocation(ForeignAllocation allocation)
EXPERIMENTAL: Wrap an allocation created outside this BufferAllocator.
|
ArrowBuf buffer(long size)
size
- The size in bytes.OutOfMemoryException
- if buffer cannot be allocatedArrowBuf buffer(long size, BufferManager manager)
size
- The size in bytes.manager
- A buffer manager to manage reallocation.OutOfMemoryException
- if buffer cannot be allocatedBufferAllocator getRoot()
BufferAllocator newChildAllocator(String name, long initReservation, long maxAllocation)
name
- the name of the allocator.initReservation
- the initial space reservation (obtained from this allocator)maxAllocation
- maximum amount of space the new allocator can allocateBufferAllocator newChildAllocator(String name, AllocationListener listener, long initReservation, long maxAllocation)
name
- the name of the allocator.listener
- allocation listener for the newly created childinitReservation
- the initial space reservation (obtained from this allocator)maxAllocation
- maximum amount of space the new allocator can allocatevoid close()
When assertions are on, complains if there are any outstanding buffers; to avoid that, release all buffers before the allocator is closed.
close
in interface AutoCloseable
long getAllocatedMemory()
long getLimit()
long getInitReservation()
void setLimit(long newLimit)
newLimit
- The new Limit to apply to allocationslong getPeakMemoryAllocation()
long getHeadroom()
boolean forceAllocate(long size)
size
- to increasevoid releaseBytes(long size)
size
- to releaseAllocationListener getListener()
AllocationListener
instance. Or AllocationListener.NOOP
by default if no listener
is configured when this allocator was created.BufferAllocator getParentAllocator()
Collection<BufferAllocator> getChildAllocators()
AllocationReservation newReservation()
AllocationReservation
ArrowBuf getEmpty()
String getName()
boolean isOverLimit()
String toVerboseString()
void assertOpen()
default RoundingPolicy getRoundingPolicy()
default ArrowBuf wrapForeignAllocation(ForeignAllocation allocation)
This is useful to integrate allocations from native code into the same memory management framework as Java-allocated buffers, presenting users a consistent API. The created buffer will be tracked by this allocator and can be transferred like Java-allocated buffers.
The underlying allocation will be closed when all references to the buffer are released. If this method throws, the underlying allocation will also be closed.
allocation
- The underlying allocation.Copyright © 2023 The Apache Software Foundation. All rights reserved.