In ODA products before version 4.3.0 memory allocation was implemented through global new and delete operators overrides. These operators were defined in TD_Alloc module and were exported from it to each ODA product. Such approach allowed to provide memory leaks catch functionality and custom reimplementation of memory management.
But this way of memory management implementation is incorrect for several reasons:
To resolve problems, listed above, since Teigha 4.3.0 the following changes in memory management mechanism have been done:
These changes mean that ODA library modules now can be independent from TD_Alloc module (except cases when odrxAlloc() / odrxFree() functions are called directly).
Please remember, that all changes mentioned above have been done for dynamic configurations.
TD_Alloc module still provides odrxAlloc() and odrxFree() functions for memory leak detecting and other memory management purposes, but does not override global new and delete operators. If you create an ODA platform extension module and TD_Alloc module is not added to the dependencies, linker generates an error. For other module types TD_Alloc module should be added to the module dependencies list. File OdAllocOp.cpp located in /Kernel/Extentions/alloc folder should be added to the project. Please, note that if you use ODAProjectGenerator script (for non-Windows platform) or executable (for Windows) platform, you do no need to add OdAllocOp.cpp file to your project, ODAProjectGenerator adds it automatically.
All heap memory allocation/deallocation operations are made through calling one of the following functions:
extern ALLOCDLL_EXPORT void* odrxAlloc (size_t nBytes);
extern ALLOCDLL_EXPORT void* odrxRealloc (void* pMemBlock, size_t newSize, size_t oldSize);
extern ALLOCDLL_EXPORT void odrxFree (void* pMemBlock);
These functions are declared in /Kernel/Include/OdAlloc.h.
Alternately, a client can define custom versions of these functions and link them with own application. ODA libraries will use the provided custom implementation of these functions, giving the client application full control of ODA heap allocation. This enables ODA software to use the same memory management as the client application.
See ExAlloc sample application for illustrating memory management customization.
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|