ADTF  3.18.3
MemoryBuffer

Memory buffer class to encapsulate and manage raw contiguously memory. More...

Public Member Functions

 MemoryBuffer ()
 Default CTOR, not allocating any memory.
 
 MemoryBuffer (std::size_t initial_size)
 CTOR with initial size of the buffer (first allocates, then zero-initializes the buffer) More...
 
 MemoryBuffer (void *buffer, std::size_t size)
 CTOR attaching to memory from a an already existing buffer (non-owning!) More...
 
 ~MemoryBuffer ()
 DTOR, either detaching any referenced buffer or deleting allocated memory.
 
 MemoryBuffer (const MemoryBuffer &other)
 Copy constructor, always allocating new memory and performing a deep copy. More...
 
MemoryBufferoperator= (const MemoryBuffer &other)
 Assignment operator, always allocating new memory and performing a deep copy. More...
 
bool allocate (std::size_t new_size)
 Allocate and zero-initialize a new memory buffer, freeing or detaching any managed memory. More...
 
void reset ()
 Reset the memory (freeing or detaching any managed memory)
 
std::size_t getSize () const
 Get the size of the currently managed memory. More...
 
void * getPtr () const
 Get raw pointer to the current buffer. More...
 
void attach (void *buffer, std::size_t size)
 Attach a pre-allocated buffer to the instance (non-owning!) More...
 
void swap (MemoryBuffer &other)
 Swap content of this object with other. More...
 

Private Attributes

std::unique_ptr< Implementation > _impl
 

Detailed Description

Memory buffer class to encapsulate and manage raw contiguously memory.

Definition at line 23 of file memorybuffer.h.

Constructor & Destructor Documentation

◆ MemoryBuffer() [1/3]

MemoryBuffer ( std::size_t  initial_size)

CTOR with initial size of the buffer (first allocates, then zero-initializes the buffer)

Parameters
[in]initial_sizeThe initial buffer size

◆ MemoryBuffer() [2/3]

MemoryBuffer ( void *  buffer,
std::size_t  size 
)

CTOR attaching to memory from a an already existing buffer (non-owning!)

Parameters
[in]bufferPointer to the pre-allocated buffer that gets attached (non-owning!)
[in]sizeSize of the memory buffer

◆ MemoryBuffer() [3/3]

MemoryBuffer ( const MemoryBuffer other)

Copy constructor, always allocating new memory and performing a deep copy.

Parameters
[in]otherOther memory buffer object to copy from.

Member Function Documentation

◆ allocate()

bool allocate ( std::size_t  new_size)

Allocate and zero-initialize a new memory buffer, freeing or detaching any managed memory.

Parameters
[in]new_sizeThe size of the new buffer (a value of zero equals reset())
Returns
true if the allocation succeeded, false otherwise

◆ attach()

void attach ( void *  buffer,
std::size_t  size 
)

Attach a pre-allocated buffer to the instance (non-owning!)

Parameters
[in]bufferPointer to the pre-allocated memory buffer
[in]sizeSize of the memory buffer

◆ getPtr()

void* getPtr ( ) const

Get raw pointer to the current buffer.

Returns
Pointer to managed memory or nullptr if no memory is managed.

◆ getSize()

std::size_t getSize ( ) const

Get the size of the currently managed memory.

Returns
Size of the currently managed memory.

◆ operator=()

MemoryBuffer& operator= ( const MemoryBuffer other)

Assignment operator, always allocating new memory and performing a deep copy.

Parameters
[in]otherOther memory buffer object to copy from.
Returns
*this

◆ swap()

void swap ( MemoryBuffer other)

Swap content of this object with other.

Parameters
[in]otherOther memory buffer object to swap the content with.