Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
Memory allocation

Memory allocation allocation

Polygon Cruncher SDK allocates objects using xNew, xNewParams, xNewArray and delete them using xDelete, xDeleteArray. (cf XMemoryMacros.h).

You can also performs in place allocation using xConstruct.
xmalloc, xfree, xrealloc allows to perform standard C allocations.
Internally all the allocations (new or malloc) are made using the standard malloc/free allocator.

You can use XMemoryCallback memoryCallbackNotify allows to get allocation notification to override this default behavior.
This might be needed on MacOS or Linux for which new and malloc are different allocators.
For example, a crash might occur, if you allocate CXXXObject on your side using new, and if CXXXObject is deleted by the SDK (which uses the free C function).
In such case, you must use Polygon Cruncher SDK allocation method (using xNew) or override the allocator using memoryCallbackNotify.
Windows uses internally the same allocator for new and malloc and such situation (using different allocation / deletion methods) might be hidden.

Tracing memory leaks

The SDK can trace memory leaks in its debug version.
This is a way to verify that you allocate and release correctly the different classes.

To activate memory leak checks, use the following code:

// InitMootoolsApplication must be set before allocating any SDK object.
// No global static object must be created too, because it will be reported as a leak.
InitMootoolsApplication("YourSerial, NULL, MOOTOOLS_APPLICATION_DEFAULT&~MOOTOOLS_APPLICATION_DISABLE_LEAKS_CHECK);
DLL_TOOLSFUNCTION void InitMootoolsApplication(const char *licenseKey, LPCTSTR applicationPath=NULL, unsigned int flags=MOOTOOLS_APPLICATION_DEFAULT, LPCTSTR logFilePath=NULL)
By default applicationPath is the executable application path. Many internal features use application...
CloseMootoolsApplication();
// Memory leaks are trace in the output debug window

This is important