Open CASCADE Technology
7.0.0
|
Open CASCADE memory manager optimized for speed. More...
#include <Standard_MMgrOpt.hxx>
Public Types | |
typedef void(* | TPCallBackFunc) (const Standard_Boolean theIsAlloc, const Standard_Address theStorage, const Standard_Size theRoundSize, const Standard_Size theSize) |
Declaration of a type pointer to the callback function that should accept the following arguments: More... | |
Public Member Functions | |
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) | |
Constructor. If aClear is True, the allocated emmory will be nullified. For description of other parameters, see description of the class above. More... | |
virtual | ~Standard_MMgrOpt () |
Frees all free lists and pools allocated for small blocks. More... | |
virtual Standard_Address | Allocate (const Standard_Size aSize) |
Allocate aSize bytes; see class description above. More... | |
virtual Standard_Address | Reallocate (Standard_Address thePtr, const Standard_Size theSize) |
Reallocate previously allocated aPtr to a new size; new address is returned. In case that aPtr is null, the function behaves exactly as Allocate. More... | |
virtual void | Free (Standard_Address thePtr) |
Free previously allocated block. Note that block can not all blocks are released to the OS by this method (see class description) More... | |
virtual Standard_Integer | Purge (Standard_Boolean isDestroyed) |
Release medium-sized blocks of memory in free lists to the system. Returns number of actually freed blocks. More... | |
![]() | |
virtual | ~Standard_MMgrRoot () |
Virtual destructor; required for correct inheritance. More... | |
Static Public Member Functions | |
static void | SetCallBackFunction (TPCallBackFunc pFunc) |
Set the callback function. You may pass 0 there to turn off the callback. The callback function, if set, will be automatically called from within Allocate and Free methods. More... | |
Protected Member Functions | |
void | Initialize () |
Internal - initialization of buffers. More... | |
Standard_Size * | AllocMemory (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. More... | |
void | FreeMemory (Standard_Address aPtr, const Standard_Size aSize) |
Internal - deallocation of memory taken by AllocMemory. More... | |
void | FreePools () |
Internal - free memory pools allocated for small size blocks. More... | |
Protected Attributes | |
Standard_Boolean | myClear |
option to clear allocated memory More... | |
Standard_Size | myFreeListMax |
last allocated index in the free blocks list More... | |
Standard_Size ** | myFreeList |
free blocks list More... | |
Standard_Size | myCellSize |
small blocks size More... | |
Standard_Integer | myNbPages |
size (pages) for small block memory pools More... | |
Standard_Size | myPageSize |
system-dependent memory page size More... | |
Standard_Size * | myAllocList |
list of memory pools for small blocks More... | |
Standard_Size * | myNextAddr |
next free address in the active memory pool More... | |
Standard_Size * | myEndBlock |
end of the active memory pool More... | |
Standard_Integer | myMMap |
non-null if using memory mapped files for allocation of large blocks More... | |
Standard_Size | myThreshold |
large block size More... | |
Standard_Mutex | myMutex |
Mutex to protect free lists data. More... | |
Standard_Mutex | myMutexPools |
Mutex to protect small block pools data. More... | |
Open CASCADE memory manager optimized for speed.
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.
typedef void(* Standard_MMgrOpt::TPCallBackFunc) (const Standard_Boolean theIsAlloc, const Standard_Address theStorage, const Standard_Size theRoundSize, const Standard_Size theSize) |
Declaration of a type pointer to the callback function that should accept the following arguments:
theIsAlloc | true if the data is allocated, false if it is freed |
theStorage | address of the allocated/freed block |
theRoundSize | the real rounded size of the block |
theSize | the size of the block that was requested by application (this value is correct only if theIsAlloc is true) |
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 |
||
) |
Constructor. If aClear is True, the allocated emmory will be nullified. For description of other parameters, see description of the class above.
|
virtual |
Frees all free lists and pools allocated for small blocks.
|
virtual |
Allocate aSize bytes; see class description above.
Implements Standard_MMgrRoot.
|
protected |
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.
|
virtual |
Free previously allocated block. Note that block can not all blocks are released to the OS by this method (see class description)
Implements Standard_MMgrRoot.
|
protected |
Internal - deallocation of memory taken by AllocMemory.
|
protected |
Internal - free memory pools allocated for small size blocks.
|
protected |
Internal - initialization of buffers.
|
virtual |
Release medium-sized blocks of memory in free lists to the system. Returns number of actually freed blocks.
Reimplemented from Standard_MMgrRoot.
|
virtual |
Reallocate previously allocated aPtr to a new size; new address is returned. In case that aPtr is null, the function behaves exactly as Allocate.
Implements Standard_MMgrRoot.
|
static |
Set the callback function. You may pass 0 there to turn off the callback. The callback function, if set, will be automatically called from within Allocate and Free methods.
|
protected |
list of memory pools for small blocks
|
protected |
small blocks size
|
protected |
option to clear allocated memory
|
protected |
end of the active memory pool
|
protected |
free blocks list
|
protected |
last allocated index in the free blocks list
|
protected |
non-null if using memory mapped files for allocation of large blocks
|
protected |
Mutex to protect free lists data.
|
protected |
Mutex to protect small block pools data.
|
protected |
size (pages) for small block memory pools
|
protected |
next free address in the active memory pool
|
protected |
system-dependent memory page size
|
protected |
large block size