- All Implemented Interfaces:
AutoCloseable
ReferenceManager and ArrowBuf can work with a custom user provided implementation
of ReferenceManager
Two important instance variables of an ArrowBuf: (1) address - starting virtual address in the underlying memory chunk that this ArrowBuf has access to (2) length - length (in bytes) in the underlying memory chunk that this ArrowBuf has access to
The management (allocation, deallocation, reference counting etc) for the memory chunk is not
done by ArrowBuf. Default implementation of ReferenceManager, allocation is in BaseAllocator, BufferLedger and AllocationManager
-
Constructor Summary
ConstructorsConstructorDescriptionArrowBuf(ReferenceManager referenceManager, @Nullable BufferManager bufferManager, long capacity, long memoryAddress) Constructs a new ArrowBuf. -
Method Summary
Modifier and TypeMethodDescriptionlongcapacity()capacity(long newCapacity) Adjusts the capacity of this buffer.voidcheckBytes(long start, long end) Allows a function to determine whether not reading a particular string of bytes is valid.clear()voidclose()booleanlongReturn that is Accounted for by this buffer (and its potentially shared siblings within the context of the associated allocator).bytegetByte(long index) Get byte value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.voidgetBytes(long index, byte[] dst) Copy data from this ArrowBuf at a given index in into destination byte array.voidgetBytes(long index, byte[] dst, int dstIndex, int length) Copy data from this ArrowBuf at a given index into destination byte array.voidgetBytes(long index, OutputStream out, int length) Copy a certain length of bytes from this ArrowBuf at a given index into the given OutputStream.voidgetBytes(long index, ByteBuffer dst) Copy data from this ArrowBuf at a given index into the destination ByteBuffer.voidCopy a given length of data from this ArrowBuf starting at a given index into a dst ArrowBuf at dstIndex.chargetChar(long index) Get char value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.doublegetDouble(long index) Get double value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.floatgetFloat(long index) Get float value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.longgetId()Get the id assigned to this ArrowBuf for debugging purposes.intgetInt(long index) Get int value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.longgetLong(long index) Get long value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.longReturns the possible memory consumed by this ArrowBuf in the worse case scenario.Get reference manager for this ArrowBuf.shortgetShort(long index) Get short value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.inthashCode()longMake a nio byte buffer from this arrowbuf.nioBuffer(long index, int length) Make a nio byte buffer from this ArrowBuf.order()Returns the byte order of elements in this buffer.voidprint(StringBuilder sb, int indent) Print detailed information of this buffer intosb.voidprint(StringBuilder sb, int indent, org.apache.arrow.memory.BaseAllocator.Verbosity verbosity) Print information of this buffer intosbat the given indentation and verbosity level.longReturns the number of bytes still available to read in this buffer.bytereadByte()Read the byte at readerIndex.voidreadBytes(byte[] dst) Read dst.length bytes at readerIndex into dst byte array.longGet the index at which the next byte will be read from.readerIndex(long readerIndex) Set the reader index for this ArrowBuf.reallocIfNeeded(long size) Returnsthisif size is less thancapacity(), otherwise delegates toBufferManager.replace(ArrowBuf, long)to get a new buffer.intrefCnt()voidsetByte(long index, byte value) Set byte value at a particular index in the underlying memory chunk this ArrowBuf has access to.voidsetByte(long index, int value) Set byte value at a particular index in the underlying memory chunk this ArrowBuf has access to.voidsetBytes(long index, byte[] src) Copy data from a given byte array into this ArrowBuf starting at a given index.voidsetBytes(long index, byte[] src, int srcIndex, long length) Copy data from a given byte array starting at the given source index into this ArrowBuf at a given index.intsetBytes(long index, InputStream in, int length) Copy a certain length of bytes from given InputStream into this ArrowBuf at the provided index.voidsetBytes(long index, ByteBuffer src) Copy data into this ArrowBuf at a given index onwards from a source ByteBuffer.voidsetBytes(long index, ByteBuffer src, int srcIndex, int length) Copy data into this ArrowBuf at a given index onwards from a source ByteBuffer starting at a given srcIndex for a certain length.voidCopy readableBytes() number of bytes from src ArrowBuf starting from its readerIndex into this ArrowBuf starting at the given index.voidCopy data from src ArrowBuf starting at index srcIndex into this ArrowBuf at given index.voidsetChar(long index, int value) Set char value at a particular index in the underlying memory chunk this ArrowBuf has access to.voidsetDouble(long index, double value) Set double value at a particular index in the underlying memory chunk this ArrowBuf has access to.voidsetFloat(long index, float value) Set float value at a particular index in the underlying memory chunk this ArrowBuf has access to.voidsetInt(long index, int value) Set int value at a particular index in the underlying memory chunk this ArrowBuf has access to.voidsetLong(long index, long value) Set long value at a particular index in the underlying memory chunk this ArrowBuf has access to.setOne(int index, int length) Deprecated.setOne(long index, long length) Sets all bits to one in the specified range.voidsetShort(long index, int value) Set short value at a particular index in the underlying memory chunk this ArrowBuf has access to.voidsetShort(long index, short value) Set short value at a particular index in the underlying memory chunk this ArrowBuf has access to.setZero(long index, long length) Zero-out the bytes in this ArrowBuf starting at the given index for the given length.slice()Returns a slice of only the readable bytes in the buffer.slice(long index, long length) Returns a slice (view) starting atindexwith the givenlength.toHexString(long start, int length) Return the buffer's byte contents in the form of a hex dump.toString()longReturns the number of bytes still available to write into this buffer before capacity is reached.voidwriteByte(byte value) Set the provided byte value at the writerIndex.voidwriteByte(int value) Set the lower order byte for the provided value at the writerIndex.voidwriteBytes(byte[] src) Write the bytes from given byte array into this ArrowBuf starting at writerIndex.voidwriteBytes(byte[] src, int srcIndex, int length) Write the bytes from given byte array starting at srcIndex into this ArrowBuf starting at writerIndex.voidwriteDouble(double value) Set the provided double value at the writerIndex.voidwriteFloat(float value) Set the provided float value at the writerIndex.voidwriteInt(int value) Set the provided int value at the writerIndex.voidwriteLong(long value) Set the provided long value at the writerIndex.longGet the index at which next byte will be written to.writerIndex(long writerIndex) Set the writer index for this ArrowBuf.voidwriteShort(int value) Set the provided int value as short at the writerIndex.
-
Constructor Details
-
ArrowBuf
public ArrowBuf(ReferenceManager referenceManager, @Nullable BufferManager bufferManager, long capacity, long memoryAddress) Constructs a new ArrowBuf.- Parameters:
referenceManager- The memory manager to track memory usage and reference count of this buffercapacity- The capacity in bytes of this buffer
-
-
Method Details
-
refCnt
public int refCnt() -
checkBytes
public void checkBytes(long start, long end) Allows a function to determine whether not reading a particular string of bytes is valid.Will throw an exception if the memory is not readable for some reason. Only doesn't something in the case that AssertionUtil.BOUNDS_CHECKING_ENABLED is true.
- Parameters:
start- The starting position of the bytes to be read.end- The exclusive endpoint of the bytes to be read.
-
getReferenceManager
Get reference manager for this ArrowBuf.- Returns:
- user provided implementation of
ReferenceManager
-
capacity
public long capacity() -
capacity
Adjusts the capacity of this buffer. Size increases are NOT supported.- Parameters:
newCapacity- Must be in the range [0, length).
-
order
Returns the byte order of elements in this buffer. -
readableBytes
public long readableBytes()Returns the number of bytes still available to read in this buffer. -
writableBytes
public long writableBytes()Returns the number of bytes still available to write into this buffer before capacity is reached. -
slice
Returns a slice of only the readable bytes in the buffer. -
slice
Returns a slice (view) starting atindexwith the givenlength. -
nioBuffer
Make a nio byte buffer from this arrowbuf. -
nioBuffer
Make a nio byte buffer from this ArrowBuf. -
memoryAddress
public long memoryAddress() -
toString
-
hashCode
public int hashCode() -
equals
-
getLong
public long getLong(long index) Get long value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be read from- Returns:
- 8 byte long value
-
setLong
public void setLong(long index, long value) Set long value at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be writtenvalue- value to write
-
getFloat
public float getFloat(long index) Get float value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be read from- Returns:
- 4 byte float value
-
setFloat
public void setFloat(long index, float value) Set float value at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be writtenvalue- value to write
-
getDouble
public double getDouble(long index) Get double value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be read from- Returns:
- 8 byte double value
-
setDouble
public void setDouble(long index, double value) Set double value at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be writtenvalue- value to write
-
getChar
public char getChar(long index) Get char value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be read from- Returns:
- 2 byte char value
-
setChar
public void setChar(long index, int value) Set char value at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be writtenvalue- value to write
-
getInt
public int getInt(long index) Get int value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be read from- Returns:
- 4 byte int value
-
setInt
public void setInt(long index, int value) Set int value at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be writtenvalue- value to write
-
getShort
public short getShort(long index) Get short value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be read from- Returns:
- 2 byte short value
-
setShort
public void setShort(long index, int value) Set short value at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be writtenvalue- value to write
-
setShort
public void setShort(long index, short value) Set short value at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be writtenvalue- value to write
-
setByte
public void setByte(long index, int value) Set byte value at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be writtenvalue- value to write
-
setByte
public void setByte(long index, byte value) Set byte value at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be writtenvalue- value to write
-
getByte
public byte getByte(long index) Get byte value stored at a particular index in the underlying memory chunk this ArrowBuf has access to.- Parameters:
index- index (0 based relative to this ArrowBuf) where the value will be read from- Returns:
- byte value
-
readByte
public byte readByte()Read the byte at readerIndex.- Returns:
- byte value
-
readBytes
public void readBytes(byte[] dst) Read dst.length bytes at readerIndex into dst byte array.- Parameters:
dst- byte array where the data will be written
-
writeByte
public void writeByte(byte value) Set the provided byte value at the writerIndex.- Parameters:
value- value to set
-
writeByte
public void writeByte(int value) Set the lower order byte for the provided value at the writerIndex.- Parameters:
value- value to be set
-
writeBytes
public void writeBytes(byte[] src) Write the bytes from given byte array into this ArrowBuf starting at writerIndex.- Parameters:
src- src byte array
-
writeBytes
public void writeBytes(byte[] src, int srcIndex, int length) Write the bytes from given byte array starting at srcIndex into this ArrowBuf starting at writerIndex.- Parameters:
src- src byte arraysrcIndex- index in the byte array where the copy will being fromlength- length of data to copy
-
writeShort
public void writeShort(int value) Set the provided int value as short at the writerIndex.- Parameters:
value- value to set
-
writeInt
public void writeInt(int value) Set the provided int value at the writerIndex.- Parameters:
value- value to set
-
writeLong
public void writeLong(long value) Set the provided long value at the writerIndex.- Parameters:
value- value to set
-
writeFloat
public void writeFloat(float value) Set the provided float value at the writerIndex.- Parameters:
value- value to set
-
writeDouble
public void writeDouble(double value) Set the provided double value at the writerIndex.- Parameters:
value- value to set
-
getBytes
public void getBytes(long index, byte[] dst) Copy data from this ArrowBuf at a given index in into destination byte array.- Parameters:
index- starting index (0 based relative to the portion of memory) this ArrowBuf has access todst- byte array to copy the data into
-
getBytes
public void getBytes(long index, byte[] dst, int dstIndex, int length) Copy data from this ArrowBuf at a given index into destination byte array.- Parameters:
index- index (0 based relative to the portion of memory this ArrowBuf has access to)dst- byte array to copy the data intodstIndex- starting index in dst byte array to copy intolength- length of data to copy from this ArrowBuf
-
setBytes
public void setBytes(long index, byte[] src) Copy data from a given byte array into this ArrowBuf starting at a given index.- Parameters:
index- starting index (0 based relative to the portion of memory) this ArrowBuf has access tosrc- byte array to copy the data from
-
setBytes
public void setBytes(long index, byte[] src, int srcIndex, long length) Copy data from a given byte array starting at the given source index into this ArrowBuf at a given index.- Parameters:
index- index (0 based relative to the portion of memory this ArrowBuf has access to)src- src byte array to copy the data fromsrcIndex- index in the byte array where the copy will start fromlength- length of data to copy from byte array
-
getBytes
Copy data from this ArrowBuf at a given index into the destination ByteBuffer.- Parameters:
index- index (0 based relative to the portion of memory this ArrowBuf has access to)dst- dst ByteBuffer where the data will be copied into
-
setBytes
Copy data into this ArrowBuf at a given index onwards from a source ByteBuffer.- Parameters:
index- index index (0 based relative to the portion of memory this ArrowBuf has access to)src- src ByteBuffer where the data will be copied from
-
setBytes
Copy data into this ArrowBuf at a given index onwards from a source ByteBuffer starting at a given srcIndex for a certain length.- Parameters:
index- index (0 based relative to the portion of memory this ArrowBuf has access to)src- src ByteBuffer where the data will be copied fromsrcIndex- starting index in the src ByteBuffer where the data copy will start fromlength- length of data to copy from src ByteBuffer
-
getBytes
Copy a given length of data from this ArrowBuf starting at a given index into a dst ArrowBuf at dstIndex.- Parameters:
index- index (0 based relative to the portion of memory this ArrowBuf has access to)dst- dst ArrowBuf where the data will be copied intodstIndex- index (0 based relative to the portion of memory dst ArrowBuf has access to)length- length of data to copy
-
setBytes
Copy data from src ArrowBuf starting at index srcIndex into this ArrowBuf at given index.- Parameters:
index- index index (0 based relative to the portion of memory this ArrowBuf has access to)src- src ArrowBuf where the data will be copied fromsrcIndex- starting index in the src ArrowBuf where the copy will begin fromlength- length of data to copy from src ArrowBuf
-
setBytes
Copy readableBytes() number of bytes from src ArrowBuf starting from its readerIndex into this ArrowBuf starting at the given index.- Parameters:
index- index index (0 based relative to the portion of memory this ArrowBuf has access to)src- src ArrowBuf where the data will be copied from
-
setBytes
Copy a certain length of bytes from given InputStream into this ArrowBuf at the provided index.- Parameters:
index- index index (0 based relative to the portion of memory this ArrowBuf has access to)in- src stream to copy fromlength- length of data to copy- Returns:
- number of bytes copied from stream into ArrowBuf
- Throws:
IOException- on failing to read from stream
-
getBytes
Copy a certain length of bytes from this ArrowBuf at a given index into the given OutputStream.- Parameters:
index- index index (0 based relative to the portion of memory this ArrowBuf has access to)out- dst stream to copy data intolength- length of data to copy- Throws:
IOException- on failing to write to stream
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
getPossibleMemoryConsumed
public long getPossibleMemoryConsumed()Returns the possible memory consumed by this ArrowBuf in the worse case scenario. (not shared, connected to larger underlying buffer of allocated memory)- Returns:
- Size in bytes.
-
getActualMemoryConsumed
public long getActualMemoryConsumed()Return that is Accounted for by this buffer (and its potentially shared siblings within the context of the associated allocator).- Returns:
- Size in bytes.
-
toHexString
Return the buffer's byte contents in the form of a hex dump.- Parameters:
start- the starting byte indexlength- how many bytes to log- Returns:
- A hex dump in a String.
-
getId
public long getId()Get the id assigned to this ArrowBuf for debugging purposes.Returns
System.identityHashCode(Object)which provides a unique identifier for this buffer without any per-instance memory overhead.- Returns:
- the identity hash code for this buffer
-
print
public void print(StringBuilder sb, int indent, org.apache.arrow.memory.BaseAllocator.Verbosity verbosity) Print information of this buffer intosbat the given indentation and verbosity level.It will include history if BaseAllocator.DEBUG is true and the verbosity.includeHistoricalLog are true.
-
print
Print detailed information of this buffer intosb.Most information will only be present if BaseAllocator.DEBUG is true.
-
readerIndex
public long readerIndex()Get the index at which the next byte will be read from.- Returns:
- reader index
-
writerIndex
public long writerIndex()Get the index at which next byte will be written to.- Returns:
- writer index
-
readerIndex
Set the reader index for this ArrowBuf.- Parameters:
readerIndex- new reader index- Returns:
- this ArrowBuf
-
writerIndex
Set the writer index for this ArrowBuf.- Parameters:
writerIndex- new writer index- Returns:
- this ArrowBuf
-
setZero
Zero-out the bytes in this ArrowBuf starting at the given index for the given length.- Parameters:
index- index index (0 based relative to the portion of memory this ArrowBuf has access to)length- length of bytes to zero-out- Returns:
- this ArrowBuf
-
setOne
Deprecated.usesetOne(long, long)instead.Sets all bits to one in the specified range.- Parameters:
index- index index (0 based relative to the portion of memory this ArrowBuf has access to)length- length of bytes to set.- Returns:
- this ArrowBuf
-
setOne
Sets all bits to one in the specified range.- Parameters:
index- index index (0 based relative to the portion of memory this ArrowBuf has access to)length- length of bytes to set.- Returns:
- this ArrowBuf
-
reallocIfNeeded
Returnsthisif size is less thancapacity(), otherwise delegates toBufferManager.replace(ArrowBuf, long)to get a new buffer. -
clear
-
setOne(long, long)instead.