Class representing (and optionally allocating) memory with a specified location and size.
More...
#include <Memory.h>
|
|
using | size_type = std::size_t |
| | Memory size/position type.
|
| |
|
using | sizeOption = std::optional<size_type> |
| | Optional memory size/position.
|
| |
|
using | Option = std::optional<Memory> |
| | Unique pointer.
|
| |
|
using | Unique = std::unique_ptr<Memory> |
| | Unique pointer.
|
| |
|
using | Shared = std::shared_ptr<Memory> |
| | Shared pointer.
|
| |
|
| static void | fill (void *start, size_type size, char fillChar=0) |
| |
| template<typename T > |
| static void | erase (T &target) |
| |
| static size_type | copy (char *dest, char *source, size_type destSize, size_type sourceSize) |
| |
template<typename T >
requires (std::is_integral_v<T>) |
| static T | toBigEndian (T val) |
| |
template<typename T >
requires (std::is_integral_v<T>) |
| static T | fromBigEndian (T val) |
| |
template<typename T >
requires (std::is_integral_v<T>) |
| static void | byteSwap (T &val) |
| |
template<typename T >
requires (std::is_integral_v<T>) |
| static void | byteSwap (T *val, size_type howMany, bool toBigEndian) |
| |
|
|
static constexpr bool | defaultEndian {std::endian::native == std::endian::big} |
| |
Class representing (and optionally allocating) memory with a specified location and size.
◆ Memory() [1/5]
| active::utility::Memory::Memory |
( |
| ) |
|
|
inline |
◆ Memory() [2/5]
template<typename T >
requires (sizeof(T) > 1) && (!std::is_pointer<T>())
| active::utility::Memory::Memory |
( |
T & | buffer, |
|
|
bool | makeCopy = false, |
|
|
bool | takeOwnership = false ) |
|
inline |
Constructor
- Parameters
-
| buffer | A buffer (where the length can be established with sizeof(T) |
| makeCopy | True to make a private (owned) copy of the data |
| takeOwnership | True for this object to take ownership of the data (must be allocated with new char[] - ignored if makeCopy == true) |
◆ Memory() [3/5]
| Memory::Memory |
( |
void * | location, |
|
|
size_type | size, |
|
|
bool | makeCopy = false, |
|
|
bool | takeOwnership = false ) |
Constructor
- Parameters
-
| location | A pointer to the data location |
| size | The length of the data source in bytes (0 = null-terminated string) |
| makeCopy | True to make a private (owned) copy of the data |
| takeOwnership | True for this object to take ownership of the data (must be allocated with new char[] - ignored if makeCopy == true) |
◆ Memory() [4/5]
| Memory::Memory |
( |
const Memory & | source | ) |
|
Copy constructor
- Parameters
-
◆ Memory() [5/5]
| Memory::Memory |
( |
Memory && | source | ) |
|
|
noexcept |
Move constructor
- Parameters
-
◆ append()
Append data to the memory allocation. NB: Makes a private copy of unowned data
- Parameters
-
| source | The data source |
| startPos | The start position of the data to append |
| howMany | The number of bytes to append from the source (nullopt = to end) |
- Returns
- A reference to this
◆ byteSwap() [1/2]
template<typename T >
requires (std::is_integral_v<T>)
| static void active::utility::Memory::byteSwap |
( |
T & | val | ) |
|
|
inlinestatic |
Byte-swap an integer value (reverse the order of bytes to change endianess)
- Parameters
-
◆ byteSwap() [2/2]
template<typename T >
requires (std::is_integral_v<T>)
| static void active::utility::Memory::byteSwap |
( |
T * | val, |
|
|
size_type | howMany, |
|
|
bool | toBigEndian ) |
|
inlinestatic |
Byte-swap an array of integer values (in the native byte-order)
- Parameters
-
| val | A pointer to the array start |
| howMany | How many values are in the array |
| toBigEndian | True if the end result should be big-endian |
◆ clear()
| void Memory::clear |
( |
bool | isReleased = true | ) |
|
Clear data copied to this memory allocation
- Parameters
-
| isReleased | True to release any memory allocation held by the object |
◆ clonePtr()
| Memory * active::utility::Memory::clonePtr |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ copy()
Copy memory from source to destination memory
- Parameters
-
| dest | The destination memory |
| source | The source memory |
| destSize | The number of bytes to copy into the destination (can be less than the total destination allocation) |
| sourceSize | The source memory size |
- Returns
- The number of bytes copied
◆ data() [1/2]
| char * active::utility::Memory::data |
( |
| ) |
|
|
inline |
Get the location of the allocated memory
- Returns
- The allocated memory location (writable)
◆ data() [2/2]
| char * active::utility::Memory::data |
( |
| ) |
const |
|
inline |
Get the location of the allocated memory
- Returns
- The allocated memory location
◆ empty()
| bool active::utility::Memory::empty |
( |
| ) |
const |
|
inline |
Determine if the memory allocation is empty
- Returns
- True if the memory allocation is empty (size() == 0 or location == nullptr)
◆ erase()
template<typename T >
| static void active::utility::Memory::erase |
( |
T & | target | ) |
|
|
inlinestatic |
Erase the memory of a target data structure (reset content to 0)
- Parameters
-
| target | The target data structure |
◆ fill() [1/2]
| void active::utility::Memory::fill |
( |
char | fillChar = 0 | ) |
|
Fill allocated memory with a specified character
- Parameters
-
| fillChar | The character to fill the allocated memory with (0 by default) |
◆ fill() [2/2]
| void Memory::fill |
( |
void * | start, |
|
|
size_type | size, |
|
|
char | fillChar = 0 ) |
|
static |
Fill memory with a specified character
- Parameters
-
| start | The memory start |
| size | The memory size |
| fillChar | The char to fill the memory with |
◆ fromBigEndian()
template<typename T >
requires (std::is_integral_v<T>)
| static T active::utility::Memory::fromBigEndian |
( |
T | val | ) |
|
|
inlinestatic |
Make a big-endian integer value suited to the host processor (no action if the host processor is already big-endian)
- Parameters
-
- Returns
- The integer suited to the host processor
◆ operator bool()
| active::utility::Memory::operator bool |
( |
| ) |
const |
|
inline |
Conversion operator
- Returns
- True if the memory allocation is not empty
◆ operator=() [1/2]
Assignment operator
- Parameters
-
| source | The object to be copied (a complete copy of the allocated memory will be made) |
- Returns
- A reference to this object
◆ operator=() [2/2]
Assignment with move operator
- Parameters
-
- Returns
- A reference to this object
◆ operator[]() [1/2]
Subscript operator
- Parameters
-
| index | Index of the byte to access |
- Returns
- A reference to this object
◆ operator[]() [2/2]
| char Memory::operator[] |
( |
size_type | index | ) |
const |
Subscript operator
- Parameters
-
| index | Index of the byte to access |
- Returns
- A reference to this object
◆ owned()
| bool active::utility::Memory::owned |
( |
| ) |
const |
|
inline |
Determine if the memory is owned by this object
- Returns
- True if the memory is owned by this object (otherwise it points to a fixed-length allocation)
◆ release()
| char * Memory::release |
( |
| ) |
|
Release ownership of the memory allocation to the caller (this will become empty)
- Returns
- The allocated memory location (caller takes ownership - nullptr returned if this object doesn't own the allocation)
◆ resize()
Resize the memory allocation. NB: Makes a private copy of unowned data
- Parameters
-
| newSize | The new allocation size |
| fillChar | Optional character to fill additional allocated memory with (nullopt = don't fill) |
- Returns
- A reference to this
◆ size()
| size_type active::utility::Memory::size |
( |
| ) |
const |
|
inline |
Get the size of the allocated memory
- Returns
- The size of the allocated memory
◆ toBigEndian()
template<typename T >
requires (std::is_integral_v<T>)
| static T active::utility::Memory::toBigEndian |
( |
T | val | ) |
|
|
inlinestatic |
Make an integer value big-endian (no action if the host processor is already big-endian)
- Parameters
-
- Returns
- The integer as big-endian
The documentation for this class was generated from the following files:
- /Users/rwessel/Documents/Development/ActiveLib/Active/Utility/Memory.h
- /Users/rwessel/Documents/Development/ActiveLib/Active/Utility/Memory.cpp