CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | Static Public Member Functions | List of all members
CppCommon::Memory Class Reference

Memory management static class. More...

#include <memory.h>

Public Member Functions

 Memory ()=delete
 
 Memory (const Memory &)=delete
 
 Memory (Memory &&)=delete
 
 ~Memory ()=delete
 
Memoryoperator= (const Memory &)=delete
 
Memoryoperator= (Memory &&)=delete
 

Static Public Member Functions

static int64_t RamTotal ()
 Total RAM in bytes. More...
 
static int64_t RamFree ()
 Free RAM in bytes. More...
 
static bool IsZero (const void *buffer, size_t size) noexcept
 Is the given memory buffer filled with zeros? More...
 
static bool IsValidAlignment (size_t alignment) noexcept
 Is the given alignment valid? More...
 
template<typename T >
static bool IsAligned (const T *address, size_t alignment=alignof(T)) noexcept
 Is the given pointer aligned? More...
 
template<typename T >
static T * Align (const T *address, size_t alignment=alignof(T), bool upwards=true) noexcept
 Align pointer (upwards or downwards) More...
 
static void ZeroFill (void *buffer, size_t size)
 Fill the given memory buffer with zeros. More...
 
static void RandomFill (void *buffer, size_t size)
 Fill the given memory buffer with random bytes. More...
 
static void CryptoFill (void *buffer, size_t size)
 Fill the given memory buffer with cryptographic strong random bytes. More...
 

Detailed Description

Memory management static class.

Provides memory management functionality such as total and free RAM available.

Thread-safe.

Definition at line 31 of file memory.h.

Constructor & Destructor Documentation

◆ Memory() [1/3]

CppCommon::Memory::Memory ( )
delete

◆ Memory() [2/3]

CppCommon::Memory::Memory ( const Memory )
delete

◆ Memory() [3/3]

CppCommon::Memory::Memory ( Memory &&  )
delete

◆ ~Memory()

CppCommon::Memory::~Memory ( )
delete

Member Function Documentation

◆ Align()

template<typename T >
T * CppCommon::Memory::Align ( const T *  address,
size_t  alignment = alignof(T),
bool  upwards = true 
)
inlinestaticnoexcept

Align pointer (upwards or downwards)

Parameters
address- Address
alignment- Alignment value. Must be a pointer of two (default is alignof(T))
upwards- Upwards flag (default is true)
Returns
Aligned address

Definition at line 29 of file memory.inl.

◆ CryptoFill()

void CppCommon::Memory::CryptoFill ( void *  buffer,
size_t  size 
)
static

Fill the given memory buffer with cryptographic strong random bytes.

Parameters
buffer- Memory buffer to fill
size- Size of memory buffer in bytes

Definition at line 136 of file memory.cpp.

◆ IsAligned()

template<typename T >
bool CppCommon::Memory::IsAligned ( const T *  address,
size_t  alignment = alignof(T) 
)
inlinestaticnoexcept

Is the given pointer aligned?

Parameters
address- Address
alignment- Alignment value. Must be a pointer of two (default is alignof(T))
Returns
'true' if the given address is aligned, 'false' if the given address is not aligned

Definition at line 19 of file memory.inl.

◆ IsValidAlignment()

bool CppCommon::Memory::IsValidAlignment ( size_t  alignment)
inlinestaticnoexcept

Is the given alignment valid?

Parameters
alignment- Alignment value. Must be a power of two.
Returns
'true' if the given alignment is valid, 'false' if the given alignment is not valid

Definition at line 13 of file memory.inl.

◆ IsZero()

bool CppCommon::Memory::IsZero ( const void *  buffer,
size_t  size 
)
staticnoexcept

Is the given memory buffer filled with zeros?

Parameters
buffer- Memory buffer
size- Size of memory buffer in bytes
Returns
'true' if the given memory buffer is filled with zeros, 'false' if the memory buffer is not filled with zeros

Definition at line 95 of file memory.cpp.

◆ operator=() [1/2]

Memory& CppCommon::Memory::operator= ( const Memory )
delete

◆ operator=() [2/2]

Memory& CppCommon::Memory::operator= ( Memory &&  )
delete

◆ RamFree()

int64_t CppCommon::Memory::RamFree ( )
static

Free RAM in bytes.

Examples
memory_memory.cpp.

Definition at line 59 of file memory.cpp.

◆ RamTotal()

int64_t CppCommon::Memory::RamTotal ( )
static

Total RAM in bytes.

Examples
memory_memory.cpp.

Definition at line 33 of file memory.cpp.

◆ RandomFill()

void CppCommon::Memory::RandomFill ( void *  buffer,
size_t  size 
)
static

Fill the given memory buffer with random bytes.

Parameters
buffer- Memory buffer to fill
size- Size of memory buffer in bytes

Definition at line 117 of file memory.cpp.

◆ ZeroFill()

void CppCommon::Memory::ZeroFill ( void *  buffer,
size_t  size 
)
static

Fill the given memory buffer with zeros.

Parameters
buffer- Memory buffer to fill
size- Size of memory buffer in bytes

Definition at line 104 of file memory.cpp.


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