Freeing memory claimed by H5Aread

Hello!

I'm writing an interface for HDF5 library for Delphi. So far I imported most of the library procedures; I can now successfully browse HDF5 files (query groups/datasets/attributes) and read data.

However I'm facing a problem regarding variable-length string attributes. When reading such attribute, HDF5 library does the memory allocation; but I couldn't find a documented way to properly free the memory.

h5dump returns the following for the attribute:

      ATTRIBUTE "description" {
         DATATYPE H5T_STRING {
            STRSIZE H5T_VARIABLE;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }

I'm now using the following code, and it seems to do the job. But using H5Dvlen_reclaim for attribute data isn't probably correct (as H5D prefix suggests).

var
   Attribute: IHDF5Attribute;
   MemType: IHDF5Type;
   Data: Pointer;
begin
   Attribute := GetAttribute(AObj, AName);
   MemType := THDF5Type.Create(
               Dll.H5Tcopy(Dll.H5T_C_S1),
               Dll.H5Tclose);
   Dll.H5Tset_size(MemType.ID, H5T_VARIABLE);
   Dll.H5Aread(Attribute.ID, MemType.ID, @Data);
   try
     // use Data
   finally
     Dll.H5Dvlen_reclaim(GetType(Attribute).ID,
       GetSpace(Attribute).ID, H5P_DEFAULT, @Data);
   end;
end;

What is the proper way to free the memory allocated by H5Aread for variable-length data?

Best wishes,
Andrey Paramonov

···

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Hi, Andrej

As a start you can use my HDF5 delphi headers and some function conversion
on the page
http://www.astro.ff.vu.lt/index.php?option=com_content&task=view&id=46&Itemi
d=62

I think it will save you time.

I think your problem is already discussed in:
http://hdf-forum.184993.n3.nabble.com/Freeing-returned-strings-tt4026607.htm
l#none

Regards,
Saulius

···

-----Original Message-----
From: Hdf-forum [mailto:hdf-forum-bounces@lists.hdfgroup.org] On Behalf Of
??? ???
Sent: Monday, February 24, 2014 3:06 PM
To: hdf-forum@lists.hdfgroup.org
Subject: [Hdf-forum] Freeing memory claimed by H5Aread

Hello!

I'm writing an interface for HDF5 library for Delphi. So far I imported most
of the library procedures; I can now successfully browse HDF5 files (query
groups/datasets/attributes) and read data.

However I'm facing a problem regarding variable-length string attributes.
When reading such attribute, HDF5 library does the memory allocation; but I
couldn't find a documented way to properly free the memory.

h5dump returns the following for the attribute:

      ATTRIBUTE "description" {
         DATATYPE H5T_STRING {
            STRSIZE H5T_VARIABLE;
            STRPAD H5T_STR_NULLTERM;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }

I'm now using the following code, and it seems to do the job. But using
H5Dvlen_reclaim for attribute data isn't probably correct (as H5D prefix
suggests).

var
   Attribute: IHDF5Attribute;
   MemType: IHDF5Type;
   Data: Pointer;
begin
   Attribute := GetAttribute(AObj, AName);
   MemType := THDF5Type.Create(
               Dll.H5Tcopy(Dll.H5T_C_S1),
               Dll.H5Tclose);
   Dll.H5Tset_size(MemType.ID, H5T_VARIABLE);
   Dll.H5Aread(Attribute.ID, MemType.ID, @Data);
   try
     // use Data
   finally
     Dll.H5Dvlen_reclaim(GetType(Attribute).ID,
       GetSpace(Attribute).ID, H5P_DEFAULT, @Data);
   end;
end;

What is the proper way to free the memory allocated by H5Aread for
variable-length data?

Best wishes,
Andrey Paramonov

--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.

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