free memory for variable length types

Hello

I'm quite novice with HDF5 could you help me with attached code, i've used
sample codes, but unfortunately they do not work. Free memory for read
buffer causes exception. What is the best method to free memory? My version
of HDF is 1.8.9. Than you.

      Exception::dontPrint();
      H5File file( "filecpp.h5", H5F_ACC_TRUNC );
      hsize_t dimsf[2]; // dataset dimensions
      dimsf[0] = 5;
      dimsf[1] = 5;
      DataSpace dataspace( 2, dimsf );
      IntType datatype( PredType::NATIVE_INT );
      datatype.setOrder( H5T_ORDER_LE );
      DataSet dataset = file.createDataSet("my dataset", datatype, dataspace
);

    StrType strArrType(PredType::C_S1,H5T_VARIABLE);

    hsize_t dims[]={4};
    const char *string_att[4] = {"string1",
                                    "str2",
                                    "strings123",
                                    "str45"};
    char* readStr[4];
    
    DataSpace dataspace2(1,dims);
    Attribute attr2=dataset.createAttribute("stringArray", strArrType,
dataspace2);
    attr2.write(strArrType, string_att);

    attr2.read(strArrType, readStr);
    
    for (int i=0; i<4; i++)
      free(readStr[i]); //causes exception

    file.close();

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/free-memory-for-variable-length-types-tp4025565.html
Sent from the hdf-forum mailing list archive at Nabble.com.

I've finally found the workaround. I've used debug configuration before, with
release everything works fine, as I understood allocation/deallocation
memory MUST have same configurations (debug/release).

I don't really like this approach but I can live with it for now.

btw HDF5 tests in src do not work either under debug

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/free-memory-for-variable-length-types-tp4025565p4025570.html
Sent from the hdf-forum mailing list archive at Nabble.com.

Hi Sahon,

I couldn't reproduce the error. One suggestion is to check for null pointer
before you free. Do you happen to know which exception you got?

Thanks,
Binh-Minh

···

-------------
The HDF Group

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of sahon
Sent: Thursday, November 08, 2012 1:42 AM
To: hdf-forum@hdfgroup.org
Subject: [Hdf-forum] free memory for variable length types

Hello

I'm quite novice with HDF5 could you help me with attached code, i've used
sample codes, but unfortunately they do not work. Free memory for read
buffer causes exception. What is the best method to free memory? My version
of HDF is 1.8.9. Than you.

      Exception::dontPrint();
      H5File file( "filecpp.h5", H5F_ACC_TRUNC );
      hsize_t dimsf[2]; // dataset dimensions
      dimsf[0] = 5;
      dimsf[1] = 5;
      DataSpace dataspace( 2, dimsf );
      IntType datatype( PredType::NATIVE_INT );
      datatype.setOrder( H5T_ORDER_LE );
      DataSet dataset = file.createDataSet("my dataset", datatype, dataspace
);

    StrType strArrType(PredType::C_S1,H5T_VARIABLE);

    hsize_t dims[]={4};
    const char *string_att[4] = {"string1",
                                    "str2",
                                    "strings123",
                                    "str45"};
    char* readStr[4];
    
    DataSpace dataspace2(1,dims);
    Attribute attr2=dataset.createAttribute("stringArray",
strArrType,
dataspace2);
    attr2.write(strArrType, string_att);

    attr2.read(strArrType, readStr);
    
    for (int i=0; i<4; i++)
      free(readStr[i]); //causes exception

    file.close();

--
View this message in context:
http://hdf-forum.184993.n3.nabble.com/free-memory-for-variable-length-types-
tp4025565.html
Sent from the hdf-forum mailing list archive at Nabble.com.

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

--
Internal Virus Database is out-of-date.
Checked by AVG.
Version: 7.5.549 / Virus Database: 270.9.0/1778 - Release Date: 11/9/2008
2:14 PM

actually it doesn't go to try..catch, IDE (VS 2008 the same VS 2010) stops
on line: *free(readStr[i]); //causes exception *

here is content of output:

HEAP[HDF2008.exe]: Invalid address specified to RtlValidateHeap( 00920000,
005CACE8 )
Windows has triggered a breakpoint in HDF2008.exe.

This may be due to a corruption of the heap, which indicates a bug in
HDF2008.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while HDF2008.exe has focus.

The output window may have more diagnostic information.

i've also attached screenshot

<http://hdf-forum.184993.n3.nabble.com/file/n4025568/hdf_free.png>

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/free-memory-for-variable-length-types-tp4025565p4025568.html
Sent from the hdf-forum mailing list archive at Nabble.com.

I think the problem is that the library currently does not provide a
matching H5XYZfree call
for some of the resources it allocates for you. Non C APIs compound the
problem and lead to the
obscure behavior you're seeing. 'free' is a well-intended guess, but still a
guess.

G.

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@hdfgroup.org] On Behalf Of sahon
Sent: Thursday, November 08, 2012 9:38 AM
To: hdf-forum@hdfgroup.org
Subject: Re: [Hdf-forum] free memory for variable length types

actually it doesn't go to try..catch, IDE (VS 2008 the same VS 2010) stops
on line: *free(readStr[i]); //causes exception *

here is content of output:

HEAP[HDF2008.exe]: Invalid address specified to RtlValidateHeap( 00920000,
005CACE8 )
Windows has triggered a breakpoint in HDF2008.exe.

This may be due to a corruption of the heap, which indicates a bug in
HDF2008.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while HDF2008.exe has focus.

The output window may have more diagnostic information.

i've also attached screenshot

<http://hdf-forum.184993.n3.nabble.com/file/n4025568/hdf_free.png>

--
View this message in context:
http://hdf-forum.184993.n3.nabble.com/free-memory-for-variable-length-types-
tp4025565p4025568.html
Sent from the hdf-forum mailing list archive at Nabble.com.

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Hi all,

I've finally found the workaround. I've used debug configuration before,
with
release everything works fine, as I understood allocation/deallocation
memory MUST have same configurations (debug/release).

All software must use the same version of the C runtime (CRT) in order to
avoid errors when CRT objects such as allocated memory are passed between
libraries and/or executables. Since Microsoft implements each CRT in a
separate library (dll), you can't allocate memory in one CRT and free it in
another without risking heap errors. You should also never statically link
to the CRT since each library/exe will have its own private version of the
CRT.

You can check the linked versions with dumpbin /imports via a Visual Studio
command prompt, though I don't think that will show static linkage.

"Same version" means 32/64-bit, debug/release, and Visual Studio version.
We currently don't distribute debug binaries though there are plans to do
so in the near future.

I'm working on a document describing this in more detail. It should appear
on the web sometime soon, hopefully this month.

Cheers,

Dana

···

On Thu, Nov 8, 2012 at 11:17 AM, sahon <ssahon@gmail.com> wrote:

Hi,

I think the solution for the problem could be found in my proposal in the
thread "Porting HDF5 to Delphi".

We should introduce a function within dll that frees memory as other XXClose
functions.

Regards,
Saulius

···

--
View this message in context: http://hdf-forum.184993.n3.nabble.com/free-memory-for-variable-length-types-tp4025565p4025572.html
Sent from the hdf-forum mailing list archive at Nabble.com.