Memory management in conversions of variable length data types

Hi

I had a question on the memory management when converting variable-length datatypes.
Taking the following code as an example

#include "H5Cpp.h"
#include <vector>

int main()
{
    std::vector<int> data{2, 3, -4, 122};
    hvl_t original{data.size(), data.data()};
    H5::VarLenType sourceType(&H5::PredType::NATIVE_INT);
    H5::VarLenType targetType(&H5::PredType::NATIVE_DOUBLE);
    // Use this to hold the converted value
    hvl_t converted = original;
    sourceType.convert(targetType, 1, &converted, nullptr);
}

If I look at the memory that converted.p points to I can see that it does contain the correct bytes to represent the same numbers as doubles (including being larger).

My question is - am I responsible for freeing the memory that converted.p points to?
I couldn’t find this information in the documentation… I don’t run into any problems if I call std::free(converted.p) (assuming I don’t then try and access the memory) but I don’t know if that’s a solid guarantee that I’m responsible for that memory.

Cheers,
Jon

Hi Jon,
are you familiar with valgrind? One way to convince yourself is to set up a rig, then check if there is any bytes left on the heap/stack upon exit.

best: steve

Jon, you own it. The C-API for cleaning up is H5Dvlen_reclaim() pre-HDF5 1.12 and H5Treclaim() in HDF5 1.12+.

Best, G.

Perfect - thanks @gheber for the confirmation!
@steven, I’m having to refamiliarise myself with valgrind right now anyway so this is a good recommendation for the future…