Memory buffer class to encapsulate and manage raw contiguously memory.
More...
|
| 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...
|
|
MemoryBuffer & | operator= (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...
|
|
|
std::unique_ptr< Implementation > | _impl |
|
Memory buffer class to encapsulate and manage raw contiguously memory.
Definition at line 23 of file memorybuffer.h.
◆ MemoryBuffer() [1/3]
CTOR with initial size of the buffer (first allocates, then zero-initializes the buffer)
- Parameters
-
[in] | initial_size | The initial buffer size |
◆ MemoryBuffer() [2/3]
CTOR attaching to memory from a an already existing buffer (non-owning!)
- Parameters
-
[in] | buffer | Pointer to the pre-allocated buffer that gets attached (non-owning!) |
[in] | size | Size of the memory buffer |
◆ MemoryBuffer() [3/3]
Copy constructor, always allocating new memory and performing a deep copy.
- Parameters
-
[in] | other | Other memory buffer object to copy from. |
◆ 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_size | The 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] | buffer | Pointer to the pre-allocated memory buffer |
[in] | size | Size of the memory buffer |
◆ getPtr()
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=()
Assignment operator, always allocating new memory and performing a deep copy.
- Parameters
-
[in] | other | Other memory buffer object to copy from. |
- Returns
*this
◆ swap()
Swap content of this
object with other
.
- Parameters
-
[in] | other | Other memory buffer object to swap the content with. |