c++ - Performance issues when reading a file from HD that dosen't follow computer byte alignments -
i have file format (.stl, stereo lithography, structure standard , can not changed. not confused standard template library) uses 50 byte data structure. reading hd directly leads wrong data being read 50 bytes not multiple of 4.
out of entire 50 byte structure, need 36 of bytes. method using right extract data manually offset read position of file point next set of data begins, read off 36 bytes temporary variable , dump data in temporary variable it's proper position on array.
here's code chunk:
threepoints* output = new threepoints [numtriangles]; // create array hold entire file threepoints* temp = new threepoints [1]; // temp variable pull data out of each "cell" // extract each triangle individualy (int = 0; < numtriangles; i++) { stlfile.seekg (96 + * 50, ios::beg); //read vertex data , put them tempoary array // offset = 80 header + 4 #triangles + 12 normal vector stlfile.read(reinterpret_cast<char*>(temp), (36)); // read next 36 data blocks holder, 3 points * 3 axis * 4 bytes per float output[i] = temp[0]; // dump values in holder proper array }
this method works slow. how go doing make faster , more efficiently?
edit: know manually disabling byte alignment solve problem need use resulting array intensively , iterate on many times. i've been told disabling byte alignment can result in performance issues, avoided it.
instead of doing bunch of small seeks & reads, allocate large buffer (say, enough 1000 structures) , read bunch of records @ once. (then iterate through buffer copying out 36-byte chunks need).
Comments
Post a Comment