Thanks all for the help, and yes I was looking to find a string element
length.  I've been using fixed-length strings previously, and so have been
passing in buffers allocated in my code to H5A/Dread(). It seemed the least
perturbation to my code now that I'm writing/reading variable length strings
would be to just copy the string from the HDF allocated string to my
pre-allocated buffer, and immediately reclaim the HDF memory. Anyhow, at
read time I can just check if it's variable-length or not, and do my own
alloc either before or after the read depending.

-Ken

On Thu, Jun 3, 2010 at 7:38 AM, Quincey Koziol <[email protected]> wrote:

>
> On Jun 3, 2010, at 9:23 AM, Mark Miller wrote:
>
> > Ah, I see. Well, that is definitely different from what I was thinking
> > he was asking. And, requires a different answer than I gave. ;)
>
>         Well, now he knows both pieces of information. :-)
>
>                Quincey
>
> > Mark
> >
> > On Thu, 2010-06-03 at 04:39, Quincey Koziol wrote:
> >> Hi Mark,
> >>
> >> On Jun 2, 2010, at 9:36 PM, Mark Miller wrote:
> >>
> >>> Yes. But the procedure you'd use depends a bit on what kind of object
> >>> you are talking about (dataset or attribute) and how you chose to
> define
> >>> the object. Did you use H5T_C_S1 as the datatype for the string? Did
> you
> >>> maybe just define a dataset/attribute of type H5T_NATIVE_CHAR and then
> >>> an 1D dataspace of some size? I think those choices effect how you'd go
> >>> about obtaining length.
> >>>
> >>> A general algorithm might look like...
> >>>
> >>>    1. whether its a dataset or attribute, you need to open it first
> >>>       (H5Dopen/H5Aopen)
> >>>    2. then get its datatype (H5Dget_type/H5Aget_type)
> >>>    3. then get the size of that datatype (H5Tget_size)
> >>>    4. Then get the size of the dataspace
> >>>    5. Use results from steps 3 and 4 to determine total size.
> >>
> >>      Actually, I think that Ken is trying to determine the actual string
> length for an individual element of a dataset or attribute, and he's correct
> that there's no way to retrieve the length before reading it in.  The method
> you describe above is correct for determining the size of the array an
> application will need to allocate for reading the strings, but the size
> returned from H5Tget_size() should be the same as sizeof(char *) (for
> variable-length strings - for variable-length sequences of another datatype,
> it should be sizeof(hvl_t)).  The memory for the actual strings themselves
> will be allocated at read time (and the malloc/free routines used can be
> controlled with H5Pset_vlen_mem_manager).
> >>
> >>      Quincey
> >>
> >>> Mark
> >>>
> >>> On Wed, 2010-06-02 at 18:55, Ken Sullivan wrote:
> >>>> Quick question, is there a way to find the length of a variable length
> >>>> string without first reading it?
> >>>>
> >>>> Thanks,
> >>>> Ken
> >>> --
> >>> Mark C. Miller, Lawrence Livermore National Laboratory
> >>> ================!!LLNL BUSINESS ONLY!!================
> >>> [email protected]      urgent: [email protected]
> >>> T:8-6 (925)-423-5901     M/W/Th:7-12,2-7 (530)-753-851
> >>>
> >>>
> >>> _______________________________________________
> >>> Hdf-forum is for HDF software users discussion.
> >>> [email protected]
> >>> http://*mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
> >>
> >>
> >> _______________________________________________
> >> Hdf-forum is for HDF software users discussion.
> >> [email protected]
> >> http://*mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
> > --
> > Mark C. Miller, Lawrence Livermore National Laboratory
> > ================!!LLNL BUSINESS ONLY!!================
> > [email protected]      urgent: [email protected]
> > T:8-6 (925)-423-5901     M/W/Th:7-12,2-7 (530)-753-851
> >
> >
> > _______________________________________________
> > Hdf-forum is for HDF software users discussion.
> > [email protected]
> > http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
>
>
> _______________________________________________
> Hdf-forum is for HDF software users discussion.
> [email protected]
> http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org
>
_______________________________________________
Hdf-forum is for HDF software users discussion.
[email protected]
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Reply via email to