ADTF  3.18.2
cMemoryBlock

Memory block class. More...

Public Types

enum  tMemoryLockFlags { ML_CURRENT = 0x01 , ML_FUTURE = 0x02 }
 Memory locking flags enumeration to control memory locking. More...
 

Public Member Functions

 cMemoryBlock ()
 Default constructor.
 
 cMemoryBlock (tSize nSize)
 Constructor which preallocates memory. More...
 
 cMemoryBlock (const cMemoryBlock &oBlock)
 Copy constructor. More...
 
virtual ~cMemoryBlock ()
 Destructor.
 
tResult Alloc (tSize nSize)
 (Re)allocates memory More...
 
tResult Resize (tSize nSize)
 (Re)allocates memory More...
 
tResult Alloc (tSize nSize, tSize nAlignment, tUInt32 ui32Flags=0)
 Allocates memory at addresses that are a multiple of an alignment value. More...
 
tVoid Free ()
 Frees all allocated memory.
 
tVoidGetPtr () const
 Get a pointer to the allocated memory. More...
 
tSize GetSize () const
 Get the amount of allocated memory in bytes. More...
 
tResult Set (const tVoid *src, tSize nByteCount)
 Copy data and adjust allocated memory size as necessary. More...
 
tResult CopyTo (tVoid *dest) const
 Copy data from the allocated memory into the provided destination buffer. More...
 
tResult Zero ()
 Sets all allocated bytes to zero. More...
 
 operator tVoid * () const
 Returns a pointer to the allocated memory or nullptr if no memory has been allocated. More...
 
tResult Swap (cMemoryBlock &refMemBlock)
 Swaps the administrated memory between two memory blocks. More...
 

Static Public Member Functions

static tVoidAllocPageAlignedMemory (tSize nSize, tSize nPageSize=0)
 use More...
 
static tVoid FreePageAlignedMemory (tVoid *pMemory)
 use More...
 
static tVoid MemCopy (tVoid *pDest, const tVoid *pSrc, tSize nCount)
 Copies data from one buffer to another. More...
 
static tVoid MemZero (tVoid *pDest, tSize nCount)
 Sets the data of a buffer to zero. More...
 
static tVoid MemSet (tVoid *pDest, tInt nValue, tSize nCount)
 Fills the data bytes of a buffer to the specified value. More...
 
static tInt MemCmp (const tVoid *pMem1, const tVoid *pMem2, tSize nCount)
 Compares the data bytes of two memory buffers. More...
 
static tResult MemLock (const tVoid *pAddress, tSize nSize)
 Locks part of the calling process's virtual address space into RAM preventing that memory from being paged to the swap area,. More...
 
static tResult MemUnlock (const tVoid *pAddress, tSize nSize)
 Unlocks part of the virtual address previously locked by cMemoryBlock::MemLock. More...
 
static tResult MemLockAll (tUInt32 nFlags)
 Locks the whole virtual address area. More...
 
static tResult MemUnlockAll ()
 Unlocks all the virtual address areas previously locked by cMemoryBlock::MemLock or cMemoryBlock::MemLockAll . More...
 

Protected Attributes

tVoidm_Ptr
 Pointer to memory block.
 
tVoidm_pBuffer
 Internal buffer.
 
tSize m_nSize
 Size of buffer.
 

Static Protected Attributes

static tUInt32 m_ui32Protector
 Protector for debugging purposes.
 
static tUInt32 m_ui32DefaultSectorSize
 Default sector size.
 

Detailed Description

Memory block class.

Assists to administrates blocks of memory by allocation, deletion etc.

Definition at line 19 of file memoryblock.h.

Member Enumeration Documentation

◆ tMemoryLockFlags

Memory locking flags enumeration to control memory locking.

Enumerator
ML_CURRENT 

Lock all pages which are currently mapped into the address space of the process.

ML_FUTURE 

Lock all pages which will become mapped into the address space of the process in the future.

Definition at line 27 of file memoryblock.h.

Constructor & Destructor Documentation

◆ cMemoryBlock() [1/2]

cMemoryBlock ( tSize  nSize)

Constructor which preallocates memory.

Parameters
nSize[in] The amount of space to allocate.

◆ cMemoryBlock() [2/2]

cMemoryBlock ( const cMemoryBlock oBlock)

Copy constructor.

Parameters
oBlock[in] Memoryblock to copy.

Member Function Documentation

◆ Alloc() [1/2]

tResult Alloc ( tSize  nSize)

(Re)allocates memory

Note
if used for reallocation, the old data is not copied into the new BUFFER
Parameters
nSize[in] The amount of space to allocate.
Returns
Standard Resutl Code.

Referenced by cFileRingBuffer< ADDITIONAL_DATA, ALIGNMENT >::cFileRingBuffer().

◆ Alloc() [2/2]

tResult Alloc ( tSize  nSize,
tSize  nAlignment,
tUInt32  ui32Flags = 0 
)

Allocates memory at addresses that are a multiple of an alignment value.

Parameters
nSize[in] The amount of space to allocate.
nAlignment[in] The alignment value, must be a power of two. If this is less then 1, the standard allocation is used
ui32Flags[in] Unused.
Returns
ERR_NOERROR if allocation was successful. ERR_INVALID_ARG if nSize is 0 ERR_MEMORY is memory could not be allocated

◆ AllocPageAlignedMemory()

static tVoid* AllocPageAlignedMemory ( tSize  nSize,
tSize  nPageSize = 0 
)
static

use

See also
cFileSystem::AllocPageAlignedMemory
Parameters
nSizeuse
See also
cFileSystem::AllocPageAlignedMemory
Parameters
nPageSizeuse
See also
cFileSystem::AllocPageAlignedMemory
Returns
use
See also
cFileSystem::AllocPageAlignedMemory

◆ CopyTo()

tResult CopyTo ( tVoid dest) const

Copy data from the allocated memory into the provided destination buffer.

Note
There are no checks for overflows in destination buffer!
Parameters
dest[in] The destination buffer.
Returns
ERR_NOERROR if data copied successful to buffer. ERR_POINTER if dest is nullptr or no buffer has been created yet
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ FreePageAlignedMemory()

static tVoid FreePageAlignedMemory ( tVoid pMemory)
static

use

See also
cFileSystem::FreePageAlignedMemory
Parameters
pMemoryuse
See also
cFileSystem::FreePageAlignedMemory
Returns
tVoid

◆ GetPtr()

tVoid* GetPtr ( ) const

Get a pointer to the allocated memory.

Returns
A pointer to the allocated memory.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Referenced by cBitSerializer::cBitSerializer(), cFileRingBuffer< ADDITIONAL_DATA, ALIGNMENT >::cFileRingBuffer(), and cFileRingBuffer< ADDITIONAL_DATA, ALIGNMENT >::FillForAlignment().

◆ GetSize()

tSize GetSize ( ) const

Get the amount of allocated memory in bytes.

Returns
The amount of allocated memory in bytes.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Referenced by cBitSerializer::cBitSerializer(), and cFileRingBuffer< ADDITIONAL_DATA, ALIGNMENT >::cFileRingBuffer().

◆ MemCmp()

static tInt MemCmp ( const tVoid pMem1,
const tVoid pMem2,
tSize  nCount 
)
static

Compares the data bytes of two memory buffers.

Note
There are no checks for overflows in the call!
Parameters
pMem1[in] The buffer1.
pMem2[in] The buffer2.
nCount[in] The amount of bytes that should be compared.
Returns
0 if the contents of both memory blocks are equal. >0 if the first byte that does not match has a greater value in pMem1 than in pMem2. <0 opposite
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Referenced by cStringPiece::Compare(), cStringPiece::operator==(), and cStringPiece::StartsWith().

◆ MemCopy()

static tVoid MemCopy ( tVoid pDest,
const tVoid pSrc,
tSize  nCount 
)
static

Copies data from one buffer to another.

Note
There are no checks for overflows in destination buffer! However, if either dest or src are nullptr, no copy operation is even attempted.
Parameters
pDest[in] The destination buffer.
pSrc[in] The source buffer.
nCount[in] The amount of bytes that should be copied.
Returns
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Referenced by cMemoryPtr::Assign(), ConverterBase< T >::CopyBytesFromBuffer(), cMemoryPtr::CopyTo(), adtf_ddl::access_element::get_array_value(), adtf_ddl::access_element::get_struct_value(), cSystem::cAdapterInfo::HandleAdapterInfo(), ConverterBase< T >::ReadSignal(), adtf_ddl::access_element::set_struct_value(), and ConverterBase< T >::WriteSignal().

◆ MemLock()

static tResult MemLock ( const tVoid pAddress,
tSize  nSize 
)
static

Locks part of the calling process's virtual address space into RAM preventing that memory from being paged to the swap area,.

Parameters
pAddress[in] Start address of memory to be locked
nSize[in] Size of memory area to be locked
Returns
Returns the standard result code.
Remarks
Memory locking and unlocking are performed in units of whole pages.

◆ MemLockAll()

static tResult MemLockAll ( tUInt32  nFlags)
static

Locks the whole virtual address area.

Parameters
nFlags[in] The flags argument is constructed as the bitwise OR of one or more flags of constants defined in enumeration {cMemoryBlock::tMemoryLockFlags}.
Returns
Returns the standard result code.

◆ MemSet()

static tVoid MemSet ( tVoid pDest,
tInt  nValue,
tSize  nCount 
)
static

Fills the data bytes of a buffer to the specified value.

Note
There are no checks for overflows in destination buffer!
Parameters
pDest[in] The destination buffer.
nValue[in] The value to set.
nCount[in] The amount of bytes that should be copied.
Returns
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ MemUnlock()

static tResult MemUnlock ( const tVoid pAddress,
tSize  nSize 
)
static

Unlocks part of the virtual address previously locked by cMemoryBlock::MemLock.

Parameters
pAddress[in] Start address of memory to be unlocked
nSize[in] Size of memory area to be unlocked
Returns
Returns the standard result code.
Remarks
Memory locking and unlocking are performed in units of whole pages.

◆ MemUnlockAll()

static tResult MemUnlockAll ( )
static

Unlocks all the virtual address areas previously locked by cMemoryBlock::MemLock or cMemoryBlock::MemLockAll .

Returns
Returns the standard result code.

◆ MemZero()

static tVoid MemZero ( tVoid pDest,
tSize  nCount 
)
static

Sets the data of a buffer to zero.

Note
There are no checks for overflows in destination buffer!
Parameters
pDest[in] The destination buffer.
nCount[in] The amount of bytes that should be copied.
Returns
void
This method is real-time safe.\nSee @ref page_real_time_safe.\n

Referenced by cFileRingBuffer< ADDITIONAL_DATA, ALIGNMENT >::cFileRingBuffer().

◆ operator tVoid *()

operator tVoid * ( ) const

Returns a pointer to the allocated memory or nullptr if no memory has been allocated.

This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ Resize()

tResult Resize ( tSize  nSize)

(Re)allocates memory

Note
if used for reallocation, the old data is copied into the new BUFFER
Parameters
nSize[in] The amount of space to allocate.
Returns
Standard Resutl Code.

◆ Set()

tResult Set ( const tVoid src,
tSize  nByteCount 
)

Copy data and adjust allocated memory size as necessary.

If nByteCount is different to the currently hold amount of memory, the previously allocated memory is free'd and nByteCount of memory is being re-allocated. Any exisiting data is lost.

Parameters
src[in] The source data. If this is nullptr, any allocated memory is freed.
nByteCount[in] The size of the source data. if this is 0, any allocated memory is freed
Returns
ERR_NOERRROR if operation went well. ERR_MEMORY If byte_count is different from the current buffer size, the current buffer is freed and a new one with a size of byte_count is allocated. Should this allocation fail, the aforementioned error is returned.

◆ Swap()

tResult Swap ( cMemoryBlock refMemBlock)

Swaps the administrated memory between two memory blocks.

Parameters
refMemBlock[in] The memory block to switch data with.
Returns
Always returns ERR_NOERROR.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ Zero()

tResult Zero ( )

Sets all allocated bytes to zero.

Returns
ERR_NOERROR if buffer set to zeroes. ERR_POINTER if currently no buffer is allocated
This method is real-time safe.\nSee @ref page_real_time_safe.\n