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: Strings, Up: Variables



6.29 Releasing Memory for a NC_STRING: nc_free_string

When a STRING is read into user memory from the file, the HDF5 library performs memory allocations for each of the variable length character arrays contained within the STRING 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 NC_STRING 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 NC_STRING array (i.e. the array of arrays), the nc_free_string function is provided.

Usage

     int nc_free_string(size_t len, char **data);
len
The number of character arrays in the array.
**data
The pointer to the data array.

Return Codes

NC_NOERR
No error.

Example

           if (nc_get_att(ncid, NC_GLOBAL, ATT_NAME, data_in)) ERR;
           ...
           if (nc_free_string(att_len, (char **)data_in)) 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