HeLP: write and read variable length string


   I write the following program to write vector of string into a
dataset in a HDF5 file

void stock_stringSet(H5File fileP, string symbol, size_t n, string
strCol, const vector<string> & writeString){

        hid_t mytype = H5Tvlen_create(H5T_NATIVE_CHAR);

        typedef struct {

                size_t len;

                void *p;

        } hv1_t;

        hv1_t writeChar[n];

        for(int i =0; i< n; i++){

                writeChar[i].p = malloc((writeString[i].size()+1) *

                writeChar[i].len = writeString[i].size() +1;

                strcpy( static_cast<char *> (writeChar[i].p),
const_cast<char *> (writeString[i].c_str()));


        hsize_t dims[] = {n};

        DataSpace dataspace (RANK, dims);

        hsize_t chunk_dims[] = {n};

        DSetCreatPropList ds_creatplist;

        ds_creatplist.setChunk(RANK, chunk_dims);


        DataSet dataset (fileP.createDataSet( ("/"+ symbol + "/"+
strCol), mytype, dataspace, ds_creatplist));

        hsize_t offset[] = {0};

        hsize_t dim_batch[] = {n};

        DataSpace mspace (RANK, dim_batch);

        dataspace.selectHyperslab (H5S_SELECT_SET, dim_batch, offset);

        dataset.write(writeChar, mytype, mspace, dataspace);


When I call the above function to create the dataset for the vector of
strings, the following errors are reported:

terminate called after throwing an instance of 'H5::DataSetIException'

Aborted (core dumped)

Look like the error happen on the last line of program

dataset.write(writeChar, mytype, mspace, dataspace);

Can anyone help. Thanks in advance.


This message is intended only for the personal and confidential use of the recipients named above. If the reader of this email is not the intended recipient, you have received this email in error and any review, dissemination, distribution or copying is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and permanently delete the copy you received. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. Neither CTC Holdings nor any affiliates (CTC) are responsible for any recommendation, solicitation, offer or agreement or any information about any transaction, customer account or account activity that may be attached to or contained in this communication. CTC accepts no liability for any content contained in the email, or any errors or omissions arising as a result of e-mail transmission. Any opinions contained in this email constitute the sender's best judgment at this time and are subject to change without notice. CTC London Limited is authorized and regulated by the Financial Services Authority.