ADTF  v2.14.3
cMemoryBlock Class Reference

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 (tUInt64 nSize)
 Constructor which preallocates memory. More...
 
 cMemoryBlock (const cMemoryBlock &oBlock)
 Copy constructor. More...
 
virtual ~cMemoryBlock ()
 Destructor.
 
tResult Alloc (tUInt64 nSize)
 (Re)allocates memory More...
 
tResult Alloc (tUInt64 nSize, tUInt64 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...
 
tUInt64 GetSize () const
 Get the amount of allocated memory in bytes. More...
 
tResult Set (const tVoid *src, tUInt64 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 void * () const
 Returns a pointer to the allocated memory or NULL 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 tInt GetDefaultSectorSize ()
 
static tInt GetSectorSize (const cString &strFilename)
 
static tVoidAllocPageAlignedMemory (tInt nSize, tInt nPageSize=0)
 
static tVoid FreePageAlignedMemory (tVoid *pMemory)
 
static tVoid MemCopy (tVoid *pDest, const tVoid *pSrc, tUInt64 nCount)
 Copies data from one buffer to another. More...
 
static tVoid MemZero (tVoid *pDest, tUInt64 nCount)
 Sets the data of a buffer to zero. More...
 
static tVoid MemSet (tVoid *pDest, tInt nValue, tUInt64 nCount)
 Fills the data bytes of a buffer to the specified value. More...
 
static tInt MemCmp (const tVoid *pMem1, const tVoid *pMem2, tUInt64 nCount)
 Compares the data bytes of two memory buffers. More...
 
static tResult MemLock (const tVoid *pAddress, tUInt64 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, tUInt64 nSize)
 Unlocks part of the virtual address previously locked by cMemoryBlock::MemLock. More...
 
static tResult MemLockAll (tInt 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

void * m_Ptr
 Pointer to memory block.
 
void * m_pBuffer
 Internal buffer.
 
tInt64 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 27 of file memoryblock.h.

Member Enumeration Documentation

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 35 of file memoryblock.h.

Constructor & Destructor Documentation

cMemoryBlock ( tUInt64  nSize)

Constructor which preallocates memory.

Parameters
nSize[in] The amount of space to allocate.
cMemoryBlock ( const cMemoryBlock oBlock)

Copy constructor.

Parameters
oBlock[in] Memoryblock to copy.

Member Function Documentation

tResult Alloc ( tUInt64  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().

tResult Alloc ( tUInt64  nSize,
tUInt64  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
static tVoid* AllocPageAlignedMemory ( tInt  nSize,
tInt  nPageSize = 0 
)
static
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 NULL or no buffer has been created yet
This method is real-time safe.
See The ADTF Real-Time Extension.
static tVoid FreePageAlignedMemory ( tVoid pMemory)
static
Deprecated:
use
See also
cFileSystem::FreePageAlignedMemory
Parameters
pMemoryuse
See also
cFileSystem::FreePageAlignedMemory
Returns
tVoid
static tInt GetDefaultSectorSize ( )
static
Deprecated:
use
See also
cFileSystem::GetDefaultSectorSize
Returns
default sector size
tVoid* GetPtr ( ) const

Get a pointer to the allocated memory.

Returns
A pointer to the allocated memory.
This method is real-time safe.
See The ADTF Real-Time Extension.

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

static tInt GetSectorSize ( const cString strFilename)
static
Deprecated:
use
See also
cFileSystem::GetSectorSize
Parameters
strFilenameuse
See also
cFileSystem::GetSectorSize
Returns
use
See also
cFileSystem::GetSectorSize
tUInt64 GetSize ( ) const

Get the amount of allocated memory in bytes.

Returns
The amount of allocated memory in bytes.
This method is real-time safe.
See The ADTF Real-Time Extension.

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

static tInt MemCmp ( const tVoid pMem1,
const tVoid pMem2,
tUInt64  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.
See The ADTF Real-Time Extension.
static tVoid MemCopy ( tVoid pDest,
const tVoid pSrc,
tUInt64  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 NULL, 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.
See The ADTF Real-Time Extension.
static tResult MemLock ( const tVoid pAddress,
tUInt64  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.
static tResult MemLockAll ( tInt  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.
static tVoid MemSet ( tVoid pDest,
tInt  nValue,
tUInt64  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.
See The ADTF Real-Time Extension.
static tResult MemUnlock ( const tVoid pAddress,
tUInt64  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.
static tResult MemUnlockAll ( )
static

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

Returns
Returns the standard result code.
static tVoid MemZero ( tVoid pDest,
tUInt64  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.
See The ADTF Real-Time Extension.
operator void * ( ) const

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

This method is real-time safe.
See The ADTF Real-Time Extension.
tResult Set ( const tVoid src,
tUInt64  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 NULL, 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.
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.
See The ADTF Real-Time Extension.
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.
See The ADTF Real-Time Extension.

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Fri Mar 22 2019 by doxygen 1.8.10)