Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. HELP -- An alternative to the getline function

HELP -- An alternative to the getline function

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++graphicsquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    webHamlet
    wrote on last edited by
    #1

    I'm running the code shown below, and it's just too slow. I'm reading 17k rows and 59 columns from a CSV file and it takes 3 minutes. My computer is not the fastest (5 year old Celeron processor) but still... I got some great suggestions yesterday: One person mentioned that I should read larger chunks of data instead of one character at a time. Problem is, I don't know how.. Can anybody help? Note: rawData and record are STL vectors. rawData.reserve(numberRecords) ; int counter=0 ; do { counter += 1 ; std::vector record ; record.reserve(numberVars) ; for(int i=0; igetline(buff,sizeof(buff),',') ; record.push_back(buff) ; } std::getline(*data,value) ; record.push_back(value) ; rawData.push_back(record) ; std::vector < std::string >::iterator j ; j=record.begin() ; record.erase(j, j+numberVars) ; } while (counter < numberRecords) ; Thanks, Hamlet

    T 2 Replies Last reply
    0
    • W webHamlet

      I'm running the code shown below, and it's just too slow. I'm reading 17k rows and 59 columns from a CSV file and it takes 3 minutes. My computer is not the fastest (5 year old Celeron processor) but still... I got some great suggestions yesterday: One person mentioned that I should read larger chunks of data instead of one character at a time. Problem is, I don't know how.. Can anybody help? Note: rawData and record are STL vectors. rawData.reserve(numberRecords) ; int counter=0 ; do { counter += 1 ; std::vector record ; record.reserve(numberVars) ; for(int i=0; igetline(buff,sizeof(buff),',') ; record.push_back(buff) ; } std::getline(*data,value) ; record.push_back(value) ; rawData.push_back(record) ; std::vector < std::string >::iterator j ; j=record.begin() ; record.erase(j, j+numberVars) ; } while (counter < numberRecords) ; Thanks, Hamlet

      T Offline
      T Offline
      The NULL Developer
      wrote on last edited by
      #2

      Alright buddy, u can use the read function to read a buffer into memory and then read byte by byte from there, check if u r reading past the buffer and if so, then only re read from the file the next chunk. And if u r really serious, u can try to implement these in a class like this:

      class CMyFile : public ifstream
      {
      void *m_pvBuffer;
      unsigned long m_ulBufferSize; // may initialize this with 4096
      unsigned long m_ulSeekPosition;

      public:
      CMyFile(void);
      ~CMyFile(void);
      CMyFile& operator>>(string& param_string);
      };

      use the read function, interpreting of buffer and various checks in the opertor>> function. the above is only a general idea and by no means a complete solution. "Do first things first, and second things not at all." — Peter Drucker.

      1 Reply Last reply
      0
      • W webHamlet

        I'm running the code shown below, and it's just too slow. I'm reading 17k rows and 59 columns from a CSV file and it takes 3 minutes. My computer is not the fastest (5 year old Celeron processor) but still... I got some great suggestions yesterday: One person mentioned that I should read larger chunks of data instead of one character at a time. Problem is, I don't know how.. Can anybody help? Note: rawData and record are STL vectors. rawData.reserve(numberRecords) ; int counter=0 ; do { counter += 1 ; std::vector record ; record.reserve(numberVars) ; for(int i=0; igetline(buff,sizeof(buff),',') ; record.push_back(buff) ; } std::getline(*data,value) ; record.push_back(value) ; rawData.push_back(record) ; std::vector < std::string >::iterator j ; j=record.begin() ; record.erase(j, j+numberVars) ; } while (counter < numberRecords) ; Thanks, Hamlet

        T Offline
        T Offline
        The NULL Developer
        wrote on last edited by
        #3

        let's say i read a chunk wih read() and then parse the chunk for commas and end-of-line separators. what happens if the chunk stops between commas or lines? hey do i really have to spoon feed u?

        {
        ...
        // read and parse
        ...

        if(.../*end of buffer reached && last character read!= terminator*/ )
        {
        ...
        //re read buffer from file
        //read and parse again
        }

        no more questions please... "Do first things first, and second things not at all." — Peter Drucker.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups