Ocean
Ocean::Memory Class Reference

This class implements an object able to allocate memory. More...

Public Member Functions

 Memory ()=default
 Creates a new object without any allocated memory. More...
 
 Memory (Memory &&memory) noexcept
 Move constructor. More...
 
 Memory (const size_t size, const size_t alignment=size_t(1))
 Creates a new object and allocates a specified amount of memory. More...
 
 Memory (void *useData, const size_t size)
 Creates a new object and uses externally allocated writable memory. More...
 
 Memory (const void *useData, const size_t size)
 Creates a new object and uses externally allocated read-only memory. More...
 
 ~Memory ()
 Releases the object and frees the memory if it holds any memory. More...
 
const void * constdata () const
 Returns the pointer to the read-only memory which is allocated by this object. More...
 
void * data ()
 Returns the pointer to the writable memory which is allocated by this object. More...
 
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. More...
 
template<typename T >
T * data (const bool checkAlignment=true)
 Returns the pointer to the writable memory which is allocated by this object. More...
 
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. More...
 
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. More...
 
void free ()
 Explicitly frees (releases) the memory before this object is released. More...
 
size_t size () const
 Returns the size of the memory in bytes. More...
 
bool isOwner () const
 Returns whether this object owns the memory. More...
 
bool isReadOnly () const
 Returns whether this object provides read-only memory only. More...
 
bool isNull () const
 Returns whether this object holds any memory. More...
 
 operator bool () const
 Returns whether this object holds any memory. More...
 
Memoryoperator= (Memory &&memory) noexcept
 Move operator. More...
 

Static Public Member Functions

template<typename T >
static Memory create (const size_t elements)
 Creates a new object and allocates enough memory necessary for 'elements' of type T. More...
 
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. More...
 
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. More...
 

Protected Member Functions

 Memory (const Memory &memory)=delete
 The disabled copy constructor. More...
 
Memoryoperator= (const Memory &memory)=delete
 The disabled assign operator. More...
 

Static Protected Member Functions

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. More...
 
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. More...
 

Protected Attributes

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. More...
 
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. More...
 
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. More...
 
size_t size_ = 0
 The size of the actual usable memory in bytes, with range [0, infinity) More...
 

Detailed Description

This class implements an object able to allocate memory.

Constructor & Destructor Documentation

◆ 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
memoryThe memory object to be moved

◆ Memory() [3/6]

Ocean::Memory::Memory ( const size_t  size,
const size_t  alignment = size_t(1) 
)
inlineexplicit

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
sizeThe size of the memory to be allocated in bytes, with range [0, infinity)
alignmentThe 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
useDataThe external allocated memory which will be used, must be valid
sizeThe 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
useDataThe external allocated memory which will be used, must be valid
sizeThe 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
memoryThe memory object that would be copied

Member Function Documentation

◆ 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
checkAlignmentTrue, 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
TThe data type of the returning pointer

◆ create()

template<typename T >
Memory Ocean::Memory::create ( const size_t  elements)
inlinestatic

Creates a new object and allocates enough memory necessary for 'elements' of type T.

Parameters
elementsThe 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
TThe 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
checkAlignmentTrue, 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
TThe 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
startThe (inclusive) pointer to the start of the memory range to be checked, must be valid
sizeThe 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
startThe (inclusive) pointer to the start of the memory range to be checked, must be valid
endThe (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
targetThe target memory receiving the memory
sourceThe source memory block
sizeNumber of bytes to be copied
workerOptional 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
targetThe target memory
sourceThe source memory
firstByteFirst byte to be copied
numberBytesNumber 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
dataMemory block to be set
valueThe value to be set, only the first byte will be used as value
sizeNumber of bytes to be set
workerOptional 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
dataMemory block to be set
valuethe value to be set
firstByteFirst byte to be set
numberBytesNumber 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]

Memory& Ocean::Memory::operator= ( const Memory memory)
protecteddelete

The disabled assign operator.

Parameters
memoryThe memory object that would be assigned

◆ operator=() [2/2]

Memory & Ocean::Memory::operator= ( Memory &&  memory)
inlinenoexcept

Move operator.

Parameters
memoryThe 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)

Field Documentation

◆ 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: