The HALCON memory management provides debugging mechanisms. The debugging is enabled with set_check('memory'), and can be switched off with set_check('~memory'). Every time a memory block is deallocated a couple of consistency checks are performed automatically. Moreover, the consistency of memory blocks can be checked for debugging reasons at any time using specific Extension Package Interface routines, see figure 3.6.
Names
HTestMem, HTestPtr, HTestAllTmp, HTestTmp
Synopsis
#include "Halcon.h" Herror HTestMem( void) Herror HTestPtr( void *pointer) Herror HTestAllTmp( Hproc_handle proc_handle) Herror HTestTmp( Hproc_handle proc_handle, void *pointer)
Figure 3.6: HALCON memory management: Check of consistency.
HTestMem checks all the memory allocated with HAlloc or HAllocLocal, whereas HTestPtr checks only the specified memory block, which must have been allocated with HAlloc. Similar to that, HTestAllTmp checks all the memory allocated via HAllocTmp, and HTestTmp checks the specified block. With any failure of the consistency check, the routines return an error code (H_ERR_ICM – inconsistent memory). Furthermore, if the global variable HDoLowError is set to true, they display a description of the error either on stderr (Unix-like systems) or within an alert box (Windows). This variable can be set in an application with the operator set_system("do_low_error","true"/"false") or used directly inside the newly written operator.