MemoryPool Class Reference
[Collections]

An application heap. More...

#include <MemoryPool.h>

Inheritance diagram for MemoryPool:
IMemoryValidate

List of all members.

Public Member Functions

 MemoryPool (const int blockSize=DEFAULT_MEMORY_POOL_BLOCK_SIZE, bool bSetMemoryData=false)
void * Malloc (int size)
void Free (void *ptr)
bool WriteMemoryDumpToFile (const char *fileName) const
bool IsValidPointer (const void *ptr) const
virtual void ValidateMem () const
virtual void CheckMem () const

Detailed Description

An application heap.

This class is the actual implementation of the IMemoryBlock - Interface. It is responsible for all MemoryRequests (GetMemory() / FreeMemory()) and manages the allocation/deallocation of Memory from the Operating-System.

Definition at line 58 of file MemoryPool.h.


Constructor & Destructor Documentation

MemoryPool::MemoryPool ( const int  blockSize = DEFAULT_MEMORY_POOL_BLOCK_SIZE,
bool  bSetMemoryData = false 
)

Contructor

Parameters:
[IN] blockSize The Size (in Bytes) each MemoryChunk can Manage. A low sMemoryChunkSize increases the MemoryPool runtime (bad), but decreases the Memory-overhead/fragmentation (good)
[IN] bSetMemoryData Set to true, if you want to set all allocated/freed Memory to a specific Value. Very usefull for debugging, but has a negativ impact on the runtime.

Definition at line 26 of file MemoryPool.cpp.

References MemoryBlock::m_data, MemoryBlock::m_next, MemoryBlock::m_pos, and MemoryBlock::m_size.


Member Function Documentation

void MemoryPool::Free ( void *  ptr  ) 

Free the allocated memory again....

Parameters:
[IN] ptrMemoryBlock Pointer to a Block of Memory, which is to be freed (previoulsy allocated via "GetMemory()").
[IN] sMemorySize Sizes (in Bytes) of Memory.

Definition at line 104 of file MemoryPool.cpp.

References MemoryBlock::m_blockId, MemoryBlock::m_freeSize, MemoryBlock::m_next, MemoryBlock::m_pos, and MemoryBlock::m_size.

bool MemoryPool::IsValidPointer ( const void *  ptr  )  const

Check, if a Pointer is in the Memory-Pool. Note : This Checks only if a pointer is inside the Memory-Pool, and not if the Memory contains meaningfull data.

Parameters:
[IN] ptrPointer Pointer to a Memory-Block which is to be checked.
Returns:
true, if the Pointer could be found in the Memory-Pool, false otherwise.

Definition at line 147 of file MemoryPool.cpp.

References MemoryBlock::m_blockId, and MemoryBlock::m_next.

void * MemoryPool::Malloc ( int  size  ) 

Get "sMemorySize" Bytes from the Memory Pool.

Parameters:
[IN] sMemorySize Sizes (in Bytes) of Memory.
Returns:
Pointer to a Memory-Block of "sMemorySize" Bytes, or NULL if an error occured.

Definition at line 60 of file MemoryPool.cpp.

References MemoryBlock::m_blockId, MemoryBlock::m_data, MemoryBlock::m_next, MemoryBlock::m_pos, and MemoryBlock::m_size.

bool MemoryPool::WriteMemoryDumpToFile ( const char *  fileName  )  const

Writes the contents of the MemoryPool to a File. Note : This file can be quite large (several MB).

Parameters:
[IN] strFileName FileName of the MemoryDump.
Returns:
true on success, false otherwise

Definition at line 131 of file MemoryPool.cpp.

References MemoryBlock::m_data, MemoryBlock::m_next, and MemoryBlock::m_size.


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