The HALCON Extension Package Interface also provides routines for permanently allocating/deallocating memory (see figures 3.4 and figure 3.5). They work similar to the standard C procedures malloc and free, but use a caching mechanism for small data blocks and provide additional debugging information.
Names
HAlloc, HRealloc, HFree, HNewImage, HNewImagePtr, HAllocXLDCont, HFreeXLDCont
Synopsis
#include "Halcon.h" Herror HAlloc( Hproc_handle proc_handle, size_t size, void **pointer) Herror HRealloc( Hproc_handle proc_handle, void *pointer size_t size, void **new_pointer) Herror HFree( Hproc_handle proc_handle, void *pointer) Herror HNewImage( Hproc_handle proc_handle, Himage *image, int kind, HIMGDIM width, HIMGDIM height) Herror HNewImagePtr( Hproc_handle proc_handle, Himage *image, int kind, HIMGDIM width, HIMGDIM height, void *data, bool initImg) Herror HAllocXLDCont( Hproc_handle proc_handle, Hcont **cont, HITEMCNT num_points) Herror HFreeXLDCont( Hproc_handle proc_handle, Hcont *cont)
Figure 3.4: General memory management within HALCON.
Note that in contrast to HAllocLocal, memory allocated by HAlloc is not deallocated automatically after the execution of a HALCON operator. Thus, this routine should be used to allocate permanent data. For example, all the iconic objects stored in the HALCON database of iconic objects are allocated with this routine (see chapter “Handling Iconic Objects and Control Parameters” and chapter “Special Routines for Typical Supply Procedures”).
HNewImage allocates raw image data inside9) the data structure Himage (see section “Pixel Data (Himage)”) based on HAlloc. Furthermore, image is initialized and the timestamp is set to the current time. The image matrix itself is initialized with 0 if 'init_new_image' has been set to 'true' using the HALCON operator set_system. This flag can be read inside HALCON using the Extension Package Interface call HReadGV.
HReadGV(proc_handle, HGInitNewImage, &init_new_img);
with init_new_img of type bool and set
HWriteGV(proc_handle, HGInitNewImage, {true,false});
Thus, it is possible to buffer the global setting of this flag, set the flag to false prior to HNewImage, and restore the old value afterwards, if you would like to prevent an initialization in any case.
HNewImagePtr does not allocate memory for the image data, but inserts the pointer data in the Himage structure image instead. For this routine, the initialization of the image data is controlled via the parameter initImg. Note that you will encounter program crashes during deallocation of image objects, if you insert a memory block that has not been allocated via HAlloc in the underlying Himage structure (see e.g., HPutImage in section “Creating Objects and Writing Output Object Parameters”).
For both HNewImage and HNewImagePtr the pixel type of the raw data within image is specified by the parameter kind. Please see figure 4.2 for the supported values.
HAllocXLDCont allocates an XLD contour10) of type Hcont (see section “XLDs (Hcont, Hpoly)”) including memory for num_points contour points. Internally this routine is based on HAlloc. HFreeXLDCont is used to deallocate a contour again (including all the points and all attributes defined for cont, see this page).
Names
HAllocRL, HAllocRLNum, HReallocRLNum, HFreeRL
Synopsis
#include "Halcon.h" Herror HAllocRL( Hproc_handle proc_handle, Hrlregion **region) Herror HAllocRLNum( Hproc_handle proc_handle, Hrlregion **region, size_t len) Herror HReallocRLNum( Hproc_handle proc_handle, Hrlregion *region size_t len, Hrlregion **new_region) Herror HFreeRL( Hproc_handle proc_handle, Hrlregion *region)
Figure 3.5: General memory management for region data.
The convenience routines HAllocRL , HAllocRLNum, HReallocRLNum, and HFreeRL (see figure 3.5) are used for handling permanent region data based on HAlloc. Otherwise, their behavior is similar to HAllocRLTmp etc. E.g., using HIncrRL (section “HIncrRL”), HAllocRL allocates more memory, see this page. Note that it is possible to change the size of regions (i.e., the number of chords) using HReallocRLNum.
| 9) So
HNewImage does not allocate memory for the Himage structure
itself.
10) In contrast to HNewImage and HNewImagePtr HAllocXLDCont also allocates memory for the structure Hcont itself, not only for the data inside that structure. |