[Hdf-forum] Store char *, std::string, or std::vector data without a copy to array?
Gordon Smith
spider.karma+hdfgroup.org at gmail.com
Tue Jan 19 19:22:57 EST 2010
On Mon, Dec 7, 2009 at 10:34 AM, Gordon Smith
<spider.karma+hdfgroup.org at gmail.com> 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 ];
> };
>
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:
DATATYPE H5T_COMPOUND {
H5T_STD_I64LE "timestamp";
H5T_VLEN { H5T_STRING {
STRSIZE 1;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
}} "value";
}
More information about the Hdf-forum
mailing list