[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: netcdf c++ class



> Organization: Texas A&M University
> Keywords: 199412082247.AA14832 C++ interface, memory leaks, ncsync

Hi Dan,

In preparing another patch file for the netCDF C++ interface, I finally got
around to looking at the problem with NcFile::sync() you reported almost two
months ago:

> I just hit a show stopper with NcFile::sync().
> 
>     for (int i = 0; i < num_dims(); i++) {
>       dimensions[i] = new NcDim(this, i);
>     }
>     for (i = 0; i < num_vars(); i++) {
>       variables[i] = new NcVar(this, i);
>     }
> 
> is a memory leak (or are memory leaks).  The
> easy fix of "delete dimensions[i];" before
> the new hoses anyone who got an NcDim* from
> you before (similary for the NcVars).  I think
> the easy way out is an NcDim::sync() and an
> NcVar::Sync() <thinking as I write>.  I'll give
> these a shot, if you see something else
> give me a holler.

I've think the best way to deal with this problem now is to just delete the
two loops entirely.  The sync() member function will still synchronize
writes to disk and subsequent reads will even detect if more records have
been added by another writer of the open file (since I don't cache this
information in the C++ interface).  The only thing lost (besides the memory
leaks) will be the ability to use new dimensions and variables that have
been added by another writer to the open file.  This is better handled by
requiring the user to close and reopen the file to see new variables and
dimensions.  Maybe there should be an NcSchema class to make schema changes
visible instead of trying to hide them under the interface.

By the way, I just went to a two-day presentation on the C++ standard
library and the Standard Template Library (STL) by Michael Vilot and Pete
Becker.  I learned a lot about library implementation and especially about
the great new STL algorithms and containers that will be part of the
standard.  When I get time, I might try designing a set of cooperating or
nested STL container classes as an interface to a netCDF dataset to see if
it works.

--Russ