windows - C++: Reading a struct with a vector from a mapped file -


i loading huge amounts of data in memory access it. until put ram. data gets huge, can not anymore. therefore using mapped file.

in file have stored vectors of "pitchmarks" audio file.

struct udtpitchmark {     int bytestart;     int bytecount; };  struct udtaudioinfo {     int bytestart;     int bytecount;     vector<udtpitchmark>pitchmarks; }; 

i have written huge vectors of "udtaudioinfo" file this:

// serialize int isize = naudioinfos.content().size(); fwrite(&isize,sizeof(int),1,outfile);  vector<udtaudioinfo>::iterator = naudioinfos.content().begin(); (;it != naudioinfos.content().end(); ++it) {     //we need know position data written      int istartpos= ftell( outfile );      fwrite(&it->bytestart,sizeof(int),1,outfile);     fwrite(&it->bytecount,sizeof(int),1,outfile);     int len = it->pitchmarks.size();     fwrite(&len,sizeof(int),1,outfile);      vector<udtpitchmark>::iterator it2 = it->pitchmarks.begin();     for(;it2 != it->pitchmarks.end(); ++it2)     {         fwrite(&it2->bytestart,sizeof(int),1,outfile);         fwrite(&it2->bytecount,sizeof(int),1,outfile);     }     //and need know length of data written     int iendpos= ftell( outfile );     int ilen=(iendpos-istartpos);     //now store file-location info in map , save map when have saved entire audio info     nmapping.add (istartpos,ilen); } 

the question if can read 1 of udtaudioinfos mapped file. not sure if possible copy such structs file variable. thank help.

if portability , particular compiler's implementation not @ issue, if vector<> stores data in order known you, can accommodate in reading file image. stl objects don't specify how store data, however.

if create small test, you'll able readily examine how vector's elements stored , you'll able work there confidence.


Comments