This class implements an object able to allocate memory.
More...
#include <Memory.h>
|
| Memory ()=default |
| Creates a new object without any allocated memory.
|
|
| Memory (Memory &&memory) noexcept |
| Move constructor.
|
|
| Memory (const size_t size, const size_t alignment=size_t(1)) |
| Creates a new object and allocates a specified amount of memory.
|
|
| Memory (void *useData, const size_t size) |
| Creates a new object and uses externally allocated writable memory.
|
|
| Memory (const void *useData, const size_t size) |
| Creates a new object and uses externally allocated read-only memory.
|
|
| ~Memory () |
| Releases the object and frees the memory if it holds any memory.
|
|
const void * | constdata () const |
| Returns the pointer to the read-only memory which is allocated by this object.
|
|
void * | data () |
| Returns the pointer to the writable memory which is allocated by this object.
|
|
template<typename T > |
const T * | constdata (const bool checkAlignment=true) const |
| Returns the pointer to the read-only memory which is allocated by this object.
|
|
template<typename T > |
T * | data (const bool checkAlignment=true) |
| Returns the pointer to the writable memory which is allocated by this object.
|
|
bool | isInside (const void *const start, const size_t size) const |
| Returns whether a specified memory range is entirely enclosed inside the memory managed by this object.
|
|
bool | isInside (const void *const start, const void *const end) const |
| Returns whether a specified memory range is entirely enclosed inside the memory managed by this object.
|
|
void | free () |
| Explicitly frees (releases) the memory before this object is released.
|
|
size_t | size () const |
| Returns the size of the memory in bytes.
|
|
bool | isOwner () const |
| Returns whether this object owns the memory.
|
|
bool | isReadOnly () const |
| Returns whether this object provides read-only memory only.
|
|
bool | isNull () const |
| Returns whether this object holds any memory.
|
|
| operator bool () const |
| Returns whether this object holds any memory.
|
|
Memory & | operator= (Memory &&memory) noexcept |
| Move operator.
|
|
|
template<typename T > |
static Memory | create (const size_t elements) |
| Creates a new object and allocates enough memory necessary for 'elements' of type T.
|
|
static void | memcpy (void *target, const void *source, const unsigned int size, Worker *worker=nullptr) |
| Copies a block of memory using a worker object to speed up the process.
|
|
static void | memset (void *data, const int value, const unsigned int size, Worker *worker=nullptr) |
| Sets the value of a given memory block using a worker object to speed up the process.
|
|
|
static void | memcpySubset (uint8_t *target, const uint8_t *source, const unsigned int firstByte, const unsigned int numberBytes) |
| Copies a subset of the a memory block.
|
|
static void | memsetSubset (uint8_t *data, const int value, const unsigned int firstByte, const unsigned int numberBytes) |
| Sets a subset of a given memory block.
|
|
|
void * | allocatedData_ = nullptr |
| The pointer to the memory which is allocated and owned by this object, this pointer is pointing to the memory which needs to be freed when disposing the memory object.
|
|
const void * | constAlignedData_ = nullptr |
| The pointer to the read-only aligned memory which is reported to be the actual memory pointer, this memory pointer must not be freed when disposing the memory object.
|
|
void * | alignedData_ = nullptr |
| The pointer to the writable aligned memory which is reported to be the actual memory pointer, this memory pointer must not be freed when disposing the memory object.
|
|
size_t | size_ = 0 |
| The size of the actual usable memory in bytes, with range [0, infinity)
|
|
This class implements an object able to allocate memory.
◆ Memory() [1/6]
Ocean::Memory::Memory |
( |
| ) |
|
|
default |
Creates a new object without any allocated memory.
◆ Memory() [2/6]
Ocean::Memory::Memory |
( |
Memory && |
memory | ) |
|
|
inlinenoexcept |
Move constructor.
- Parameters
-
memory | The memory object to be moved |
◆ Memory() [3/6]
Creates a new object and allocates a specified amount of memory.
This function allows to allocated memory with a specific byte alignment, so that the start address of the memory is a multiple of the specified alignment.
- Parameters
-
size | The size of the memory to be allocated in bytes, with range [0, infinity) |
alignment | The memory byte alignment of the allocated memory, in bytes, with range [1, infinity) |
◆ Memory() [4/6]
Ocean::Memory::Memory |
( |
void * |
useData, |
|
|
const size_t |
size |
|
) |
| |
|
inline |
Creates a new object and uses externally allocated writable memory.
This object will not be the owner of the memory, ensure that the external memory exists as long as this object exists.
- Parameters
-
useData | The external allocated memory which will be used, must be valid |
size | The size of the external allocated memory, in bytes, with range [1, infinity) |
◆ Memory() [5/6]
Ocean::Memory::Memory |
( |
const void * |
useData, |
|
|
const size_t |
size |
|
) |
| |
|
inline |
Creates a new object and uses externally allocated read-only memory.
This object will not be the owner of the memory, ensure that the external memory exists as long as this object exists.
- Parameters
-
useData | The external allocated memory which will be used, must be valid |
size | The size of the external allocated memory, in bytes, with range [1, infinity) |
◆ ~Memory()
Ocean::Memory::~Memory |
( |
| ) |
|
|
inline |
Releases the object and frees the memory if it holds any memory.
◆ Memory() [6/6]
Ocean::Memory::Memory |
( |
const Memory & |
memory | ) |
|
|
protecteddelete |
The disabled copy constructor.
- Parameters
-
memory | The memory object that would be copied |
◆ constdata() [1/2]
const void * Ocean::Memory::constdata |
( |
| ) |
const |
|
inline |
Returns the pointer to the read-only memory which is allocated by this object.
- Returns
- The memory allocated by this object, nullptr if no memory is allocated
◆ constdata() [2/2]
template<typename T >
const T * Ocean::Memory::constdata |
( |
const bool |
checkAlignment = true | ) |
const |
|
inline |
Returns the pointer to the read-only memory which is allocated by this object.
- Parameters
-
checkAlignment | True, to apply an assert checking the byte alignment of the specified data type |
- Returns
- The memory allocated by this object, nullptr if no memory is allocated
- Template Parameters
-
T | The data type of the returning pointer |
◆ create()
Creates a new object and allocates enough memory necessary for 'elements' of type T.
- Parameters
-
elements | The number of elements of type T for which the new object will allocate memory, with range [0, infinity) |
- Returns
- The new memory object
- Template Parameters
-
T | The data type of the each element |
◆ data() [1/2]
void * Ocean::Memory::data |
( |
| ) |
|
|
inline |
Returns the pointer to the writable memory which is allocated by this object.
- Returns
- The memory allocated by this object, nullptr if no memory is allocated
◆ data() [2/2]
template<typename T >
T * Ocean::Memory::data |
( |
const bool |
checkAlignment = true | ) |
|
|
inline |
Returns the pointer to the writable memory which is allocated by this object.
- Parameters
-
checkAlignment | True, to apply an assert checking the byte alignment of the specified data type |
- Returns
- The memory allocated by this object, nullptr if no memory is allocated
- Template Parameters
-
T | The data type of the returning pointer |
◆ free()
void Ocean::Memory::free |
( |
| ) |
|
|
inline |
Explicitly frees (releases) the memory before this object is released.
◆ isInside() [1/2]
bool Ocean::Memory::isInside |
( |
const void *const |
start, |
|
|
const size_t |
size |
|
) |
| const |
|
inline |
Returns whether a specified memory range is entirely enclosed inside the memory managed by this object.
- Parameters
-
start | The (inclusive) pointer to the start of the memory range to be checked, must be valid |
size | The size of the memory range to be checked, in bytes, with range [0, infinity) |
- Returns
- True, if so or if 'size == 0'
◆ isInside() [2/2]
bool Ocean::Memory::isInside |
( |
const void *const |
start, |
|
|
const void *const |
end |
|
) |
| const |
|
inline |
Returns whether a specified memory range is entirely enclosed inside the memory managed by this object.
- Parameters
-
start | The (inclusive) pointer to the start of the memory range to be checked, must be valid |
end | The (exclusive) pointer to the first byte after the memory range to be checked, must be valid, with range [start, infinity) |
- Returns
- True, if so or if 'start == end'
◆ isNull()
bool Ocean::Memory::isNull |
( |
| ) |
const |
|
inline |
Returns whether this object holds any memory.
- Returns
- True, if so
◆ isOwner()
bool Ocean::Memory::isOwner |
( |
| ) |
const |
|
inline |
Returns whether this object owns the memory.
- Returns
- True, if the memory is owned; False, if the memory is owned externally
◆ isReadOnly()
bool Ocean::Memory::isReadOnly |
( |
| ) |
const |
|
inline |
Returns whether this object provides read-only memory only.
- Returns
- True, if the memory is read-only; False, if the memory is writable
◆ memcpy()
void Ocean::Memory::memcpy |
( |
void * |
target, |
|
|
const void * |
source, |
|
|
const unsigned int |
size, |
|
|
Worker * |
worker = nullptr |
|
) |
| |
|
inlinestatic |
Copies a block of memory using a worker object to speed up the process.
- Parameters
-
target | The target memory receiving the memory |
source | The source memory block |
size | Number of bytes to be copied |
worker | Optional worker object |
◆ memcpySubset()
void Ocean::Memory::memcpySubset |
( |
uint8_t * |
target, |
|
|
const uint8_t * |
source, |
|
|
const unsigned int |
firstByte, |
|
|
const unsigned int |
numberBytes |
|
) |
| |
|
inlinestaticprotected |
Copies a subset of the a memory block.
- Parameters
-
target | The target memory |
source | The source memory |
firstByte | First byte to be copied |
numberBytes | Number of bytes to be copied |
◆ memset()
void Ocean::Memory::memset |
( |
void * |
data, |
|
|
const int |
value, |
|
|
const unsigned int |
size, |
|
|
Worker * |
worker = nullptr |
|
) |
| |
|
inlinestatic |
Sets the value of a given memory block using a worker object to speed up the process.
- Parameters
-
data | Memory block to be set |
value | The value to be set, only the first byte will be used as value |
size | Number of bytes to be set |
worker | Optional worker object |
◆ memsetSubset()
void Ocean::Memory::memsetSubset |
( |
uint8_t * |
data, |
|
|
const int |
value, |
|
|
const unsigned int |
firstByte, |
|
|
const unsigned int |
numberBytes |
|
) |
| |
|
inlinestaticprotected |
Sets a subset of a given memory block.
- Parameters
-
data | Memory block to be set |
value | the value to be set |
firstByte | First byte to be set |
numberBytes | Number of bytes to be set |
◆ operator bool()
Ocean::Memory::operator bool |
( |
| ) |
const |
|
inlineexplicit |
Returns whether this object holds any memory.
- Returns
- True, if so
◆ operator=() [1/2]
The disabled assign operator.
- Parameters
-
memory | The memory object that would be assigned |
◆ operator=() [2/2]
Move operator.
- Parameters
-
memory | The memory object to be moved |
◆ size()
size_t Ocean::Memory::size |
( |
| ) |
const |
|
inline |
Returns the size of the memory in bytes.
- Returns
- The memory's size in bytes, with range [0, infinity)
◆ alignedData_
void* Ocean::Memory::alignedData_ = nullptr |
|
protected |
The pointer to the writable aligned memory which is reported to be the actual memory pointer, this memory pointer must not be freed when disposing the memory object.
◆ allocatedData_
void* Ocean::Memory::allocatedData_ = nullptr |
|
protected |
The pointer to the memory which is allocated and owned by this object, this pointer is pointing to the memory which needs to be freed when disposing the memory object.
◆ constAlignedData_
const void* Ocean::Memory::constAlignedData_ = nullptr |
|
protected |
The pointer to the read-only aligned memory which is reported to be the actual memory pointer, this memory pointer must not be freed when disposing the memory object.
◆ size_
size_t Ocean::Memory::size_ = 0 |
|
protected |
The size of the actual usable memory in bytes, with range [0, infinity)
The documentation for this class was generated from the following file: