Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
arrow::Buffer Class Reference

Object containing a pointer to a piece of contiguous memory with a particular size. More...

#include <arrow/buffer.h>

Inheritance diagram for arrow::Buffer:
arrow::gpu::CudaBuffer arrow::MutableBuffer arrow::py::NumPyBuffer arrow::py::PyBuffer arrow::py::PyForeignBuffer arrow::gpu::CudaHostBuffer arrow::ResizableBuffer

Public Member Functions

 Buffer (const uint8_t *data, int64_t size)
 Construct from buffer and size without copying memory. More...
 
 Buffer (const std::string &data)
 Construct from std::string without copying memory. More...
 
virtual ~Buffer ()=default
 
 Buffer (const std::shared_ptr< Buffer > &parent, const int64_t offset, const int64_t size)
 An offset into data that is owned by another buffer, but we want to be able to retain a valid pointer to it even after other shared_ptr's to the parent buffer have been destroyed. More...
 
bool is_mutable () const
 
bool Equals (const Buffer &other, int64_t nbytes) const
 Return true if both buffers are the same size and contain the same bytes up to the number of compared bytes. More...
 
bool Equals (const Buffer &other) const
 Return true if both buffers are the same size and contain the same bytes. More...
 
Status Copy (const int64_t start, const int64_t nbytes, MemoryPool *pool, std::shared_ptr< Buffer > *out) const
 Copy a section of the buffer into a new Buffer. More...
 
Status Copy (const int64_t start, const int64_t nbytes, std::shared_ptr< Buffer > *out) const
 Copy a section of the buffer using the default memory pool into a new Buffer. More...
 
void ZeroPadding ()
 Zero bytes in padding, i.e. bytes between size_ and capacity_. More...
 
std::string ToString () const
 Copy buffer contents into a new std::string. More...
 
int64_t capacity () const
 
const uint8_t * data () const
 
uint8_t * mutable_data ()
 
int64_t size () const
 
std::shared_ptr< Bufferparent () const
 

Static Public Member Functions

static Status FromString (const std::string &data, MemoryPool *pool, std::shared_ptr< Buffer > *out)
 Construct a new buffer that owns its memory from a std::string. More...
 
static Status FromString (const std::string &data, std::shared_ptr< Buffer > *out)
 Construct a new buffer that owns its memory from a std::string using the default memory pool. More...
 
static std::shared_ptr< BufferFromString (std::string &&data)
 Construct an immutable buffer that takes ownership of the contents of an std::string. More...
 
template<typename T , typename SizeType = int64_t>
static std::shared_ptr< BufferWrap (const T *data, SizeType length)
 Create buffer referencing typed memory with some length without copying. More...
 
template<typename T >
static std::shared_ptr< BufferWrap (const std::vector< T > &data)
 Create buffer referencing std::vector with some length without copying. More...
 

Protected Member Functions

void CheckMutable () const
 

Protected Attributes

bool is_mutable_
 
const uint8_t * data_
 
uint8_t * mutable_data_
 
int64_t size_
 
int64_t capacity_
 
std::shared_ptr< Bufferparent_
 

Detailed Description

Object containing a pointer to a piece of contiguous memory with a particular size.

Base class does not own its memory

Buffers have two related notions of length: size and capacity. Size is the number of bytes that might have valid data. Capacity is the number of bytes that where allocated for the buffer in total.

The following invariant is always true: Size < Capacity

Constructor & Destructor Documentation

◆ Buffer() [1/3]

arrow::Buffer::Buffer ( const uint8_t *  data,
int64_t  size 
)
inline

Construct from buffer and size without copying memory.

Parameters
[in]dataa memory buffer
[in]sizebuffer size
Note
The passed memory must be kept alive through some other means

◆ Buffer() [2/3]

arrow::Buffer::Buffer ( const std::string &  data)
inlineexplicit

Construct from std::string without copying memory.

Parameters
[in]dataa std::string object
Note
The std::string must stay alive for the lifetime of the Buffer, so temporary rvalue strings must be stored in an lvalue somewhere

◆ ~Buffer()

virtual arrow::Buffer::~Buffer ( )
virtualdefault

◆ Buffer() [3/3]

arrow::Buffer::Buffer ( const std::shared_ptr< Buffer > &  parent,
const int64_t  offset,
const int64_t  size 
)
inline

An offset into data that is owned by another buffer, but we want to be able to retain a valid pointer to it even after other shared_ptr's to the parent buffer have been destroyed.

This method makes no assertions about alignment or padding of the buffer but in general we expected buffers to be aligned and padded to 64 bytes. In the future we might add utility methods to help determine if a buffer satisfies this contract.

Member Function Documentation

◆ capacity()

int64_t arrow::Buffer::capacity ( ) const
inline

◆ CheckMutable()

void arrow::Buffer::CheckMutable ( ) const
protected

◆ Copy() [1/2]

Status arrow::Buffer::Copy ( const int64_t  start,
const int64_t  nbytes,
MemoryPool pool,
std::shared_ptr< Buffer > *  out 
) const

Copy a section of the buffer into a new Buffer.

◆ Copy() [2/2]

Status arrow::Buffer::Copy ( const int64_t  start,
const int64_t  nbytes,
std::shared_ptr< Buffer > *  out 
) const

Copy a section of the buffer using the default memory pool into a new Buffer.

◆ data()

const uint8_t* arrow::Buffer::data ( ) const
inline

◆ Equals() [1/2]

bool arrow::Buffer::Equals ( const Buffer other,
int64_t  nbytes 
) const

Return true if both buffers are the same size and contain the same bytes up to the number of compared bytes.

◆ Equals() [2/2]

bool arrow::Buffer::Equals ( const Buffer other) const

Return true if both buffers are the same size and contain the same bytes.

◆ FromString() [1/3]

static Status arrow::Buffer::FromString ( const std::string &  data,
MemoryPool pool,
std::shared_ptr< Buffer > *  out 
)
static

Construct a new buffer that owns its memory from a std::string.

Parameters
[in]dataa std::string object
[in]poola memory pool
[out]outthe created buffer
Returns
Status message

◆ FromString() [2/3]

static Status arrow::Buffer::FromString ( const std::string &  data,
std::shared_ptr< Buffer > *  out 
)
static

Construct a new buffer that owns its memory from a std::string using the default memory pool.

◆ FromString() [3/3]

static std::shared_ptr<Buffer> arrow::Buffer::FromString ( std::string &&  data)
static

Construct an immutable buffer that takes ownership of the contents of an std::string.

Parameters
[in]dataan rvalue-reference of a string
Returns
a new Buffer instance

◆ is_mutable()

bool arrow::Buffer::is_mutable ( ) const
inline

◆ mutable_data()

uint8_t* arrow::Buffer::mutable_data ( )
inline

◆ parent()

std::shared_ptr<Buffer> arrow::Buffer::parent ( ) const
inline

◆ size()

int64_t arrow::Buffer::size ( ) const
inline

◆ ToString()

std::string arrow::Buffer::ToString ( ) const

Copy buffer contents into a new std::string.

Returns
std::string
Note
Can throw std::bad_alloc if buffer is large

◆ Wrap() [1/2]

template<typename T , typename SizeType = int64_t>
static std::shared_ptr<Buffer> arrow::Buffer::Wrap ( const T *  data,
SizeType  length 
)
inlinestatic

Create buffer referencing typed memory with some length without copying.

Parameters
[in]datathe typed memory as C array
[in]lengththe number of values in the array
Returns
a new shared_ptr<Buffer>

◆ Wrap() [2/2]

template<typename T >
static std::shared_ptr<Buffer> arrow::Buffer::Wrap ( const std::vector< T > &  data)
inlinestatic

Create buffer referencing std::vector with some length without copying.

Parameters
[in]datathe vector to be referenced. If this vector is changed, the buffer may become invalid
Returns
a new shared_ptr<Buffer>

◆ ZeroPadding()

void arrow::Buffer::ZeroPadding ( )
inline

Zero bytes in padding, i.e. bytes between size_ and capacity_.

Member Data Documentation

◆ capacity_

int64_t arrow::Buffer::capacity_
protected

◆ data_

const uint8_t* arrow::Buffer::data_
protected

◆ is_mutable_

bool arrow::Buffer::is_mutable_
protected

◆ mutable_data_

uint8_t* arrow::Buffer::mutable_data_
protected

◆ parent_

std::shared_ptr<Buffer> arrow::Buffer::parent_
protected

◆ size_

int64_t arrow::Buffer::size_
protected

The documentation for this class was generated from the following file: