3.2.1   Temporary Data

Names

    HAllocTmp, HFreeTmp, HFreeNTmp, HFreeUpToTmp, HFreeAllTmp,
    HAllocRLTmp, HAllocRLNumTmp, HFreeRLTmp


Synopsis

    #include "Halcon.h"

    Herror HAllocTmp(       Hproc_handle proc_handle,
                            void         **pointer,
                            size_t       size)

    Herror HFreeTmp(        Hproc_handle proc_handle,
                            void         *pointer)

    Herror HFreeUpToTmp(    Hproc_handle proc_handle,
                            void         *pointer)

    Herror HFreeAllTmp(     Hproc_handle proc_handle)

    Herror HAllocRLTmp(     Hproc_handle proc_handle,
                            Hrlregion    **region)

    Herror HAllocRLNumTmp(  Hproc_handle proc_handle,
                            Hrlregion    **region,
                            size_t       size)

    Herror HFreeRLTmp(      Hproc_handle proc_handle,
                            Hrlregion    *region)

Figure 3.1: HALCON stack management for temporary data.

Figure 3.1 shows HALCON routines to allocate/deallocate temporary memory blocks. Internally, those blocks are stored within a stack. Therefore, the memory must be deallocated in reverse order of it's allocation. There are two major advantages of using these routines:

HAllocTmp is used for arbitrary data with the corresponding deallocation routine HFreeTmp. HFreeUpToTmp deallocates all recently allocated blocks up to (and including) the specified block. HFreeAllTmp deallocates all temporary blocks.

HAllocRLTmp and HAllocRLNumTmp are convenience routines that are based on HAllocTmp. HAllocRLTmp allocates as much memory as is necessary for the largest region currently stored in the HALCON database of iconic objects (the minimal size is DEF_RL_LENGTH = 50000 chords). Using HIncrRL (section “HIncrRL”), HAllocRLTmp allocates more memory. HAllocRLNumTmp allows to determine the size of memory to be allocated by specifying the number of chords. Furthermore, HAllocRLTmp and HAllocRLNumTmp initialize the data structure Hrlregion for the new region (see section “Region Data (Hrlregion)” for a description of Hrlregion). Note, that since these routines are based on HAllocTmp the corresponding memory blocks are interleaved with the blocks allocated directly via HAllocTmp. This has to be considered while deallocating the corresponding memory.



Temporary data on arbitrary heap positions

Names

    HAllocLocal, HReallocLocal, HFreeLocal,
    HAllocRLLocal, HAllocRLNumLocal, HReallocRLNumLocal, HFreeRLLocal



Synopsis

    #include "Halcon.h"

    Herror HAllocLocal(        Hproc_handle proc_handle,
                               size_t       size,
                               void         **pointer)

    Herror HReallocLocal(      Hproc_handle proc_handle,
                               void         *pointer
                               size_t       size,
                               void         **new_pointer)

    Herror HFreeLocal(         Hproc_handle proc_handle,
                               void         *pointer)

    Herror HAllocRLLocal(      Hproc_handle proc_handle,
                               Hrlregion    **region)

    Herror HAllocRLNumLocal(   Hproc_handle proc_handle,
                               Hrlregion    **region,
                               size_t       num)

    Herror HReallocRLNumLocal( Hproc_handle proc_handle,
                               Hrlregion    *region
                               size_t       num_new,
                               Hrlregion    **new_region)

    Herror HFreeRLLocal(       Hproc_handle proc_handle,
                               Hrlregion    *region)

Figure 3.2: Temporary data on arbitrary heap positions.

The temporary data management routines described so far use a stack. This is of advantage concerning runtime, but it lacks flexibility if you do not want to deallocate memory in a fixed order again. Therefore, HALCON also provides routines for allocating temporary memory on an arbitrary position of the heap, see figure 3.2. Memory blocks allocated by HAllocLocal can be deallocated by HFreeLocal in an arbitrary order. However, similar to the stack-based temporary data management, all these blocks are automatically deallocated at the end of a HALCON operator. Again this mainly aims on preventing memory leaks in case of errors. As usual, the routine HReallocLocal is used to allocate a new memory block with modified size while preserving the data of the original memory block. The latter is deallocated. So never try to access pointer subsequent to HReallocLocal– use new_pointer exclusively.

The convenience routines HAllocRLLocal , HAllocRLNumLocal HReallocRLNumLocal, and HFreeRLLocal are used for handling temporary region data based on HAllocLocal. Otherwise their behavior is similar to HAllocRLTmp etc., see above. E.g., using HIncrRL (section “HIncrRL”), HAllocRLLocal allocates more memory. However, note that it is possible to change the size of regions (i.e., the number of chords) using this set of routines (HReallocRLNumLocal) since the underlying memory blocks are not allocated within the internal stacks.



Handle Data

Name

    HAllocOutputHandle



Synopsis

    #include "Halcon.h"

    Herror HAllocOutputHandle(        Hproc_handle    proc_handle,
                                      int             par,
                                      Hphandle        elem,
                                      H_HANDLE_TYPE   HHandleInfo)

Figure 3.3: Memory management for handles.

The routine HAllocOutputHandle allocates one handle in the output control parameter par. HHandleInfo holds handle type information. elem is modified to point to where the new tool can be allocated.

The output control variable gains ownership of the pointer in elem. When aborting an operator with an error, the value must not be cleared inside the operator's code, but will be cleared automatically when cleaning the output control variable.