Next: , Previous: nc_inq_vlen, Up: User Defined Data Types


5.24 Releasing Memory for a Variable Length Array (VLEN) Type: nc_free_vlen

When a VLEN is read into user memory from the file, the HDF5 library performs memory allocations for each of the variable length arrays contained within the VLEN structure. This memory must be freed by the user to avoid memory leaks.

This violates the normal netCDF expectation that the user is responsible for all memory allocation. But, with VLEN arrays, the underlying HDF5 library allocates the memory for the user, and the user is responsible for deallocating that memory.

To save the user the trouble calling free() on each element of the VLEN array (i.e. the array of arrays), the nc_free_vlen function is provided.

Usage

     int nc_free_vlen(nc_vlen_t *vl);
vl
A pointer to the variable length array structure which is to be freed.

Errors

NC_NOERR
No error.
NC_EBADTYPE
Can't find the typeid.

Example

This example is from test program libsrc4/tst_vl.c.

        /* Free the memory used in our phony data. */
        for (i=0; i<DIM_LEN; i++)
           if (nc_free_vlen(&data[i])) ERR;