I'm trying to improve some file loading & have the following;
Code:fHandle.seekg(0,std::ios::end); ////fHandle is fstream. std::streampos length = fHandle.tellg(); fHandle.seekg(0,std::ios::beg); vector<char> buffer(length); fHandle.read(&buffer,length); stringstream streambuffer; //streambuffer.rdbuf()->pubsetbuf(&buffer,length); //1.0 crashes with this on large files ? Memory usage also increases substantially. //2.0 compiles & loads file except has issue with extracting data beyond first lot of bytes. string stringtemp = &buffer; streambuffer.str(stringtemp); //data extraction unsigned int Data = 0; int filepos = 0; streambuffer.seekg(filepos); streambuffer.read((char*)&Data,4); //data beyond this can not get extracted ? i.e. following will not extract data properly. filepos = 4; streambuffer.seekg(filepos); streambuffer.read((char*)&Data,4);
Problem is, one (1) alternative crashes on large files. The second (2) method has an issue with extracting data. So I'm wondering what am I doing wrong; or even, if there's a better/more efficient way of handling this.