OCCT3D OCCT 8.0.1
OCCT documentation

Search guides and API reference

Enter at least two characters.

    Open CASCADE Technology Reference Manual 8.0.1
    Standard_MMgrOpt Class Reference

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

    #include <Standard_MMgrOpt.hxx>

    Inheritance diagram for Standard_MMgrOpt:

    Public Types

    typedef void(* TPCallBackFunc) (const bool theIsAlloc, void *const theStorage, const size_t theRoundSize, const size_t theSize)
     Declaration of a type pointer to the callback function that should accept the following arguments:

    Public Member Functions

     Standard_MMgrOpt (const bool aClear=true, const bool aMMap=true, const size_t aCellSize=200, const int aNbPages=10000, const size_t aThreshold=40000)
     Constructor. If aClear is True, the allocated emmory will be nullified. For description of other parameters, see description of the class above.
     ~Standard_MMgrOpt () override
     Frees all free lists and pools allocated for small blocks.
    voidAllocate (const size_t aSize) override
     Allocate aSize bytes; see class description above.
    voidReallocate (void *thePtr, const size_t theSize) override
     Reallocate previously allocated aPtr to a new size; new address is returned. In case that aPtr is null, the function behaves exactly as Allocate.
    void Free (void *thePtr) override
     Free previously allocated block. Note that block can not all blocks are released to the OS by this method (see class description).
    int Purge (bool isDestroyed) override
     Release medium-sized blocks of memory in free lists to the system. Returns number of actually freed blocks.
    Public Member Functions inherited from Standard_MMgrRoot
    virtual ~Standard_MMgrRoot ()
     Virtual destructor; required for correct inheritance.

    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.

    Protected Member Functions

    void Initialize ()
     Internal - initialization of buffers.
    size_t * AllocMemory (size_t &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 (void *aPtr, const size_t aSize)
     Internal - deallocation of memory taken by AllocMemory.
    void FreePools ()
     Internal - free memory pools allocated for small size blocks.

    Protected Attributes

    bool myClear
     option to clear allocated memory
    size_t myFreeListMax
     last allocated index in the free blocks list
    size_t ** myFreeList
     free blocks list
    size_t myCellSize
     small blocks size
    int myNbPages
     size (pages) for small block memory pools
    size_t myPageSize
     system-dependent memory page size
    size_t * myAllocList
     list of memory pools for small blocks
    size_t * myNextAddr
     next free address in the active memory pool
    size_t * myEndBlock
     end of the active memory pool
    int myMMap
     non-null if using memory mapped files for allocation of large blocks
    size_t myThreshold
     large block size
    std::mutex myMutex
     Mutex to protect free lists data.
    std::mutex myMutexPools
     Mutex to protect small block pools data.

    Detailed Description

    Open CASCADE memory manager optimized for speed.

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

    • Small blocks with size less than or equal to aCellSize are allocated in big pools of memory. The parameter aNbPages specifies size of these pools in pages (operating system-dependent). When freed, small block is not returned to the system but added into free blocks list and reused when block of the same size is requested.
    • Medium size blocks with size less than aThreshold are allocated using malloc() or calloc() function but not returned to the system when method Free() is called; instead they are put into free list and reused when block of the same size is requested. Blocks of medium size stored in free lists can be released to the system (by free()) by calling method Purge().
    • Large blocks with size greater than or equal to aThreshold are allocated and freed directly: either using malloc()/calloc() and free(), or using memory mapped files (if option aMMap is True)

    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.

    Member Typedef Documentation

    ◆ TPCallBackFunc

    typedef void(* Standard_MMgrOpt::TPCallBackFunc) (const bool theIsAlloc, void *const theStorage, const size_t theRoundSize, const size_t theSize)

    Declaration of a type pointer to the callback function that should accept the following arguments:

    Parameters
    theIsAlloctrue if the data is allocated, false if it is freed
    theStorageaddress of the allocated/freed block
    theRoundSizethe real rounded size of the block
    theSizethe size of the block that was requested by application (this value is correct only if theIsAlloc is true)

    Constructor & Destructor Documentation

    ◆ Standard_MMgrOpt()

    Standard_MMgrOpt::Standard_MMgrOpt ( const bool aClear = true,
    const bool aMMap = true,
    const size_t aCellSize = 200,
    const int aNbPages = 10000,
    const size_t aThreshold = 40000 )

    Constructor. If aClear is True, the allocated emmory will be nullified. For description of other parameters, see description of the class above.

    ◆ ~Standard_MMgrOpt()

    Standard_MMgrOpt::~Standard_MMgrOpt ( )
    override

    Frees all free lists and pools allocated for small blocks.

    Member Function Documentation

    ◆ Allocate()

    void * Standard_MMgrOpt::Allocate ( const size_t aSize)
    overridevirtual

    Allocate aSize bytes; see class description above.

    Implements Standard_MMgrRoot.

    ◆ AllocMemory()

    size_t * Standard_MMgrOpt::AllocMemory ( size_t & aSize)
    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.

    ◆ Free()

    void Standard_MMgrOpt::Free ( void * thePtr)
    overridevirtual

    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.

    ◆ FreeMemory()

    void Standard_MMgrOpt::FreeMemory ( void * aPtr,
    const size_t aSize )
    protected

    Internal - deallocation of memory taken by AllocMemory.

    ◆ FreePools()

    void Standard_MMgrOpt::FreePools ( )
    protected

    Internal - free memory pools allocated for small size blocks.

    ◆ Initialize()

    void Standard_MMgrOpt::Initialize ( )
    protected

    Internal - initialization of buffers.

    ◆ Purge()

    int Standard_MMgrOpt::Purge ( bool isDestroyed)
    overridevirtual

    Release medium-sized blocks of memory in free lists to the system. Returns number of actually freed blocks.

    Reimplemented from Standard_MMgrRoot.

    ◆ Reallocate()

    void * Standard_MMgrOpt::Reallocate ( void * thePtr,
    const size_t theSize )
    overridevirtual

    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.

    ◆ SetCallBackFunction()

    void Standard_MMgrOpt::SetCallBackFunction ( TPCallBackFunc pFunc)
    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.

    Field Documentation

    ◆ myAllocList

    size_t* Standard_MMgrOpt::myAllocList
    protected

    list of memory pools for small blocks

    ◆ myCellSize

    size_t Standard_MMgrOpt::myCellSize
    protected

    small blocks size

    ◆ myClear

    bool Standard_MMgrOpt::myClear
    protected

    option to clear allocated memory

    ◆ myEndBlock

    size_t* Standard_MMgrOpt::myEndBlock
    protected

    end of the active memory pool

    ◆ myFreeList

    size_t** Standard_MMgrOpt::myFreeList
    protected

    free blocks list

    ◆ myFreeListMax

    size_t Standard_MMgrOpt::myFreeListMax
    protected

    last allocated index in the free blocks list

    ◆ myMMap

    int Standard_MMgrOpt::myMMap
    protected

    non-null if using memory mapped files for allocation of large blocks

    ◆ myMutex

    std::mutex Standard_MMgrOpt::myMutex
    protected

    Mutex to protect free lists data.

    ◆ myMutexPools

    std::mutex Standard_MMgrOpt::myMutexPools
    protected

    Mutex to protect small block pools data.

    ◆ myNbPages

    int Standard_MMgrOpt::myNbPages
    protected

    size (pages) for small block memory pools

    ◆ myNextAddr

    size_t* Standard_MMgrOpt::myNextAddr
    protected

    next free address in the active memory pool

    ◆ myPageSize

    size_t Standard_MMgrOpt::myPageSize
    protected

    system-dependent memory page size

    ◆ myThreshold

    size_t Standard_MMgrOpt::myThreshold
    protected

    large block size


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