Store char *, std::string, or std::vector data without a copy to array?

Hello -

I'm writing a number of datatypes to HDF5 successfully using a struct
similar to this:

    struct FooMemoryType_t {
        boost::int64_t timestamp_;
        char data_[ Foo::DATA_LENGTH ];

The data length varies for each type.
The char data originates in std::string and/or std::vector of char:

    struct FooNetworkType_t {
        boost::int64_t timestamp_;
        std::string< char> data_;

The network data is therefore copied into the memory type for HDF write.
Is there a way to avoid such a copy using only a reference or pointer to the
network data assuming the network structure cannot be changed?

I did attempt the following, but H5Tinsert clearly needs an offset to actual
bytes in FooMemoryType_t.

    struct FooMemoryType_t {
        boost::int64_t timestamp_;
        const char * data_p_;

    compoundTypeID = H5Tcreate( H5T_COMPOUND, sizeof( FooMemoryType_t ) );
    hid_t stringTypeID = H5Tcopy( H5T_C_S1 );
    result = H5Tset_size( stringTypeID, Foo::DATA_LENGTH );
    result = H5Tinsert( compoundTypeID, "Packet", HOFFSET( FooMemoryType_t,
data_p_ ), stringTypeID );


To write data without a copy, using a variable length type works:

struct VariableMemType {
    boost::int64_t timestamp;
    hvl_t vData;
} scratch;

hid_t vDatatypeID = H5Tvlen_create( H5T_C_S1 );

memDatatypeID = H5Tcreate( H5T_COMPOUND, sizeof( VariableMemType ) );
H5Tinsert( memDatatypeID, "timestamp", HOFFSET ( VariableMemType,
timestamp ), H5T_STD_I64LE );
H5Tinsert( memDatatypeID, "value", HOFFSET( VariableMemType, vData ),
vDatatypeID );
H5Tclose( vDatatypeID );

scratch.timestamp = timestamp;
scratch.vData.len = length;
scratch.vData.p = ( void * ) data_p;
status = H5Dwrite( datasetID, memDatatypeID, memDataspaceID,
fileDataspaceID, plistID, & scratch );

Result is the following:

         H5T_STD_I64LE "timestamp";
         H5T_VLEN { H5T_STRING {
            STRSIZE 1;
            CSET H5T_CSET_ASCII;
            CTYPE H5T_C_S1;
         }} "value";


On Mon, Dec 7, 2009 at 10:34 AM, Gordon Smith <> wrote:

Hello -

I'm writing a number of datatypes to HDF5 successfully using a struct
similar to this:

struct FooMemoryType\_t \{
    boost::int64\_t timestamp\_;
    char data\_\[ Foo::DATA\_LENGTH \];