Re: Strings

Elena Pourmal <epourmal@xxxxxxxxxxxxx> writes:

> I believe you just allocate array of char pointers, then library does
> the rest. You only have to use
> H5Dvlen_reclaim function after you are done. See tvlstr.c test in the
> test directory.
>
> Elena
>

Howdy Elena!

Well, looking at tvlstr.c was very interesting, and it leads to lots
of questions!

I am looking at function test_write_vl_string_attribute().

_From the code below it's clear that no space is allocated for
string_att_check before the H5Aread is called.

And then H5free(string_att_check) is called. Is H5free documented
anywhere on-line? I can't find it...

In this case it seems that you are writing a scalar string, and you
don't have to allocate space when reading it. Which makes sense. But
where does H5free come in to it? The user must call this function
after reading the string, right?

Will H5Dvlen_reclaim with for scalar strings? Or must the user use
H5free?

Thanks,

Ed

static void test_write_vl_string_attribute(void)
{
    hid_t file, root, dataspace, att;
    hid_t type;
    herr_t ret;
    char *string_att_check;

    /* Open the file */
    file = H5Fopen(DATAFILE, H5F_ACC_RDWR, H5P_DEFAULT);
    CHECK(file, FAIL, "H5Fopen");

    /* Create a datatype to refer to. */
    type = H5Tcopy (H5T_C_S1);
    CHECK(type, FAIL, "H5Tcopy");

    ret = H5Tset_size (type, H5T_VARIABLE);
    CHECK(ret, FAIL, "H5Tset_size");

    root = H5Gopen(file, "/");
    CHECK(root, FAIL, "H5Gopen");

    dataspace = H5Screate(H5S_SCALAR);
    CHECK(dataspace, FAIL, "H5Screate");

    /* Test creating a "normal" sized string attribute */
    att = H5Acreate(root, "test_scalar", type, dataspace, H5P_DEFAULT);
    CHECK(att, FAIL, "H5Acreate");

    ret = H5Awrite(att, type, &string_att);
    CHECK(ret, FAIL, "H5Awrite");

    ret = H5Aread(att, type, &string_att_check);
    CHECK(ret, FAIL, "H5Aread");


...
-- 
Ed Hartnett  -- ed@xxxxxxxxxxxxxxxx