Dev Essential
Loading...
Searching...
No Matches
a_util::memory::MemoryBuffer Class Reference

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

#include <memorybuffer.h>

Public Member Functions

 MemoryBuffer ()
 Default CTOR, not allocating any memory.
 
 MemoryBuffer (std::size_t initial_size)
 
 MemoryBuffer (void *buffer, std::size_t size)
 
 ~MemoryBuffer ()
 DTOR, either detaching any referenced buffer or deleting allocated memory.
 
 MemoryBuffer (const MemoryBuffer &other)
 
MemoryBufferoperator= (const MemoryBuffer &other)
 
bool allocate (std::size_t new_size)
 
void reset ()
 
std::size_t getSize () const
 
void * getPtr () const
 
void attach (void *buffer, std::size_t size)
 
void swap (MemoryBuffer &other)
 

Detailed Description

Memory buffer class to encapsulate and manage raw contiguously memory.

Constructor & Destructor Documentation

◆ MemoryBuffer() [1/3]

a_util::memory::MemoryBuffer::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]

a_util::memory::MemoryBuffer::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]

a_util::memory::MemoryBuffer::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 a_util::memory::MemoryBuffer::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 a_util::memory::MemoryBuffer::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 * a_util::memory::MemoryBuffer::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 a_util::memory::MemoryBuffer::getSize ( ) const

Get the size of the currently managed memory.

Returns
Size of the currently managed memory.

◆ operator=()

MemoryBuffer & a_util::memory::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

◆ reset()

void a_util::memory::MemoryBuffer::reset ( )

Reset the memory (freeing or detaching any managed memory)

◆ swap()

void a_util::memory::MemoryBuffer::swap ( MemoryBuffer & other)

Swap content of this object with other

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

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