Thread: file IO speed over network

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Well in conclusion here i tried a buffered version and effectively its the same speed over the network, maybe a little quicker. I ended up using the char buffer directly rather than via an istringstream as it seemed to be taxing the memory of my pc and going a bit bonkers otherwise.

    The data was a .csv of
    file size 494mb!
    1.7million rows
    Once the data is in the buffer then it outputs the data in 2 or 3 seconds, but the loading time prior to this is about 56 seconds, so all told i think this is about the same as my original version just looping until ifstream eof and getline direct from ifstream. Obviously the buffer version is much better if i was to go on and do some parsing or needed to reread etc.

    Here is the relevant bit of code i decided to use:

    Code:
       
    //opened file ok....
    //..
    
                cout << "\n\nLoading file..\n";
                int length = 0;
                inFile.seekg (0, ios::end);
                length = inFile.tellg();
                inFile.seekg (0, ios::beg);
    
                char* buffer = NULL;
                buffer = new char[length];
                inFile.read(buffer, length);
                inFile.close();
    
                cout << "\n\nCounting rows..\n";
    
                int count = 0;
                for(int i = 0; i < length; i++)
                {
                    if(buffer[i] == '\n')
                    count++;
                }            
                cout << "\n\nTotal Rows: " << count << "\n\n";
                
                delete[] buffer;
    Last edited by rogster001; 09-05-2011 at 05:55 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. to receive image file through network port
    By nadeem athani in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-03-2011, 08:50 PM
  2. Speed of pointers vs. speed of arrays/structs
    By Kempelen in forum C Programming
    Replies: 32
    Last Post: 06-27-2008, 10:16 AM
  3. file transfer across network
    By kris.c in forum Networking/Device Communication
    Replies: 6
    Last Post: 06-17-2006, 01:08 PM
  4. Network File Copy in DR DOS
    By daron in forum C Programming
    Replies: 3
    Last Post: 09-30-2005, 01:49 AM
  5. File I/O on Network drive, Quick Question
    By kransk in forum C++ Programming
    Replies: 3
    Last Post: 11-24-2003, 09:17 AM