Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

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



5.23 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;
 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Office of Programs University Corporation for Atmospheric Research (UCAR)   Unidata is a member of the UCAR Office of Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690