OCC Main Page | FoundationClasses | Toolkits | Packages | Class Hierarchy | Data Structures | File List | Data Fields | Globals

FoundationClasses
TKernel
Standard


Standard_MMgrOpt Class Reference

Open CASCADE memory manager optimized for speed. More...

#include <Standard_MMgrOpt.hxx>

Inheritance diagram for Standard_MMgrOpt:

Inheritance graph
[legend]

Public Member Functions

Standard_EXPORT Standard_MMgrOpt (const Standard_Boolean aClear=Standard_True, const Standard_Boolean aMMap=Standard_True, const Standard_Size aCellSize=200, const Standard_Integer aNbPages=10000, const Standard_Size aThreshold=40000, const Standard_Boolean isReentrant=Standard_False)
 Constructor. If aClear is True, the allocated emmory will be nullified. For description of other parameters, see description of the class above.
virtual Standard_EXPORT ~Standard_MMgrOpt ()
 Frees all free lists and pools allocated for small blocks.
virtual Standard_EXPORT Standard_Address Allocate (const Standard_Size aSize)
 Allocate aSize bytes; see class description above.
virtual Standard_EXPORT Standard_Address Reallocate (Standard_Address &aPtr, const Standard_Size aSize)
 Reallocate previously allocated aPtr to a new size; aPtr is nullified.
virtual Standard_EXPORT void Free (Standard_Address &aPtr)
 Free previously allocated block; aPtr is nullified. Note that block can not all blocks are released to the OS by this method (see class description).
virtual Standard_EXPORT Standard_Integer Purge (Standard_Boolean isDestroyed)
 Release medium-sized blocks of memory in free lists to the system. Returns number of actually freed blocks.
virtual Standard_EXPORT void SetReentrant (Standard_Boolean isReentrant)
 Set reentrant mode on or off. Note: This method may be called only when no any other thread can access this object simultaneously.

Protected Member Functions

Standard_EXPORT void Initialize ()
 Internal - initialization of buffers.
Standard_SizeAllocMemory (Standard_Size &aSize)
 Internal - allocation of memory using either malloc or memory mapped files. The size of the actually allocated block may be greater than requested one when memory mapping is used, since it is aligned to page size.
void FreeMemory (Standard_Address aPtr, const Standard_Size aSize)
 Internal - deallocation of memory taken by AllocMemory.
void FreePools ()
 Internal - free memory pools allocated for small size blocks.

Protected Attributes

Standard_Boolean myClear
 option to clear allocated memory
Standard_Size myFreeListMax
 last allocated index in the free blocks list
Standard_Size ** myFreeList
 free blocks list
Standard_Size myCellSize
 small blocks size
Standard_Integer myNbPages
 size (pages) for small block memory pools
Standard_Size myPageSize
 system-dependent memory page size
Standard_SizemyAllocList
 list of memory pools for small blocks
Standard_SizemyNextAddr
 next free address in the active memory pool
Standard_SizemyEndBlock
 end of the active memory pool
Standard_Integer myMMap
 non-null if using memory mapped files for allocation of large blocks
Standard_Size myThreshold
 large block size
Standard_Mutex myMutex
 Mutex to protect free lists data.
Standard_Mutex myMutexPools
 Mutex to protect small block pools data.
Standard_Boolean myReentrant
 Use mutex to provide correct reentrant behaviour.

Detailed Description

The behaviour is different for memory blocks of different sizes, according to specified options provided to constructor:

Thus the optimization of memory allocation/deallocation is reached for small and medium size blocks using free lists method; note that space allocated for small blocks cannot be (currently) released to the system while space for medium size blocks can be released by method Purge().

Note that destructor of that class frees all free lists and memory pools allocated for small blocks.

Note that size of memory blocks allocated by this memory manager is always rounded up to 16 bytes. In addition, 8 bytes are added at the beginning of the memory block to hold auxiliary information (size of the block when in use, or pointer to the next free block when in free list). This the expense of speed optimization. At the same time, allocating small blocks is usually less costly than directly by malloc since allocation is made once (when allocating a pool) and overheads induced by malloc are minimized.


Constructor & Destructor Documentation

Standard_EXPORT Standard_MMgrOpt::Standard_MMgrOpt const Standard_Boolean  aClear = Standard_True,
const Standard_Boolean  aMMap = Standard_True,
const Standard_Size  aCellSize = 200,
const Standard_Integer  aNbPages = 10000,
const Standard_Size  aThreshold = 40000,
const Standard_Boolean  isReentrant = Standard_False
 

virtual Standard_EXPORT Standard_MMgrOpt::~Standard_MMgrOpt  )  [virtual]
 


Member Function Documentation

virtual Standard_EXPORT Standard_Address Standard_MMgrOpt::Allocate const Standard_Size  aSize  )  [virtual]
 

Implements Standard_MMgrRoot.

Standard_Size* Standard_MMgrOpt::AllocMemory Standard_Size aSize  )  [protected]
 

virtual Standard_EXPORT void Standard_MMgrOpt::Free Standard_Address aPtr  )  [virtual]
 

Implements Standard_MMgrRoot.

void Standard_MMgrOpt::FreeMemory Standard_Address  aPtr,
const Standard_Size  aSize
[protected]
 

void Standard_MMgrOpt::FreePools  )  [protected]
 

Standard_EXPORT void Standard_MMgrOpt::Initialize  )  [protected]
 

virtual Standard_EXPORT Standard_Integer Standard_MMgrOpt::Purge Standard_Boolean  isDestroyed  )  [virtual]
 

Reimplemented from Standard_MMgrRoot.

virtual Standard_EXPORT Standard_Address Standard_MMgrOpt::Reallocate Standard_Address aPtr,
const Standard_Size  aSize
[virtual]
 

Implements Standard_MMgrRoot.

virtual Standard_EXPORT void Standard_MMgrOpt::SetReentrant Standard_Boolean  isReentrant  )  [virtual]
 

Reimplemented from Standard_MMgrRoot.


Field Documentation

Standard_Size* Standard_MMgrOpt::myAllocList [protected]
 

Standard_Size Standard_MMgrOpt::myCellSize [protected]
 

Standard_Boolean Standard_MMgrOpt::myClear [protected]
 

Standard_Size* Standard_MMgrOpt::myEndBlock [protected]
 

Standard_Size** Standard_MMgrOpt::myFreeList [protected]
 

Standard_Size Standard_MMgrOpt::myFreeListMax [protected]
 

Standard_Integer Standard_MMgrOpt::myMMap [protected]
 

Standard_Mutex Standard_MMgrOpt::myMutex [protected]
 

Standard_Mutex Standard_MMgrOpt::myMutexPools [protected]
 

Standard_Integer Standard_MMgrOpt::myNbPages [protected]
 

Standard_Size* Standard_MMgrOpt::myNextAddr [protected]
 

Standard_Size Standard_MMgrOpt::myPageSize [protected]
 

Standard_Boolean Standard_MMgrOpt::myReentrant [protected]
 

Standard_Size Standard_MMgrOpt::myThreshold [protected]
 


The documentation for this class was generated from the following file:
Generated on Mon Aug 25 13:13:21 2008 for OpenCASCADE by  doxygen 1.4.1