string & stringstream issue/Q?

This is a discussion on string & stringstream issue/Q? within the C++ Programming forums, part of the General Programming Boards category; hi, I'm trying to improve some file loading & have the following; Code: fHandle.seekg(0,std::ios::end); ////fHandle is fstream. std::streampos length = ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Location
    Australia
    Posts
    55

    string & stringstream issue/Q?

    hi,

    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[0],length);
    
            stringstream streambuffer;
            //streambuffer.rdbuf()->pubsetbuf(&buffer[0],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[0];
            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.

    Cheers
    Last edited by Tropod; 01-14-2011 at 11:48 PM.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,739
    If this file is record based, you should focus on extracting all the records one at a time.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Location
    Australia
    Posts
    55
    Quote Originally Posted by whiteflags View Post
    If this file is record based, you should focus on extracting all the records one at a time.

    The data is not records based, it varies between all different sorts of file types. And the large(er) file(s) where it crashes, is 700MB~ or so.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21