LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Having Issue with Array Resizing

A slightly more efficient way is to create the roiptr once when you create the handle and then always use that rather than the actual roi handle:

 

roiptr = ffi.new("RoiArray*", AllocateRoiArray(100))
if (roiptr[0]!=0)
    print("Size of Roi Array: ", roiptr[0][0][0].dimSize)
    err = dll.ResizeRoiArray(roiptr, 55)
    if (err==0)
        if (roiptr[0]!=0)
            print("New size: ", roiptr[0][0][0].dimSize)
        else
            print("Resize1 returned a null handle")
        err = dll.ResizeRoiArray(roiptr, 0)
        if (err==0)
            if (roiptr[0]!=0)
                print("New size: ", roiptr[0][0][0].dimSize)
            else
                print("Resize2 returned a null handle")
        else
            print("Resize2 returned error: ", err)
    else
        print("Resize1 returned error: ", err)
    # The check here is probably not needed as the DeAllocate
    # function will check for a valid handle before attempting
    # to dispose of it and all its contents.
    if (roiptr[0]!=0)
        # This should be always called as resizing to 0 is not guaranteed
        # to deallocate the array, but usually does
        err = DeAllocateRoiArray(roiptr);
else
    print("Allocation of Roi array failed")

 

And if you now complain that this is all very involved and complicated I have to tell you that this is exactly how you SHOULD program in C to be safe and if you use Pythons FFI, you do in fact program C despite that you are in Python.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 11 of 11
(40 Views)