Last visit was: It is currently Sun Aug 09, 2020 7:18 am


All times are UTC-05:00




Post new topic Reply to topic  [3 posts ] 
    Author Message
     Post subject:How to write data to a "file" in memory
    PostPosted:Fri May 14, 2010 10:43 pm 
    User avatar
     

    Joined:Sat Mar 11, 2006 8:28 am
    Posts:365
    Location:Canada
    I'm writing a program in C++ where I need to write to a file every loop. Now writing to the file every loop is very inefficient... How would I write to the file in memory and saving the data to the HDD at the end?

    The file will be a comma separated file with anywhere from 100 to 100 000 rows or more.

    Maybe just to be safe and to free up memory, save every 1 000 entries or something.

    _________________
    Best file compression around: "DEL *.*" = 100% compression
    "640K ought to be enough for anybody." - Bill Gates, 1981


    Top
    Offline  
     Post subject:Re: How to write data to a "file" in memory
    PostPosted:Sat May 15, 2010 11:41 am 
    External Project Staff
    User avatar
     

    Joined:Sun Oct 30, 2005 3:40 pm
    Posts:371
    Website:http://idlesoft.net
    Location:~/
    Code:
    while(!done) { buffer = ""; for(1 to 1000) { data = do_stuff() append(buffer, data) } write(file, buffer) }
    Pseudocode hurray!

    _________________
    -- ChaosR

    Image


    Top
    Offline  
     Post subject:Re: How to write data to a "file" in memory
    PostPosted:Sat May 15, 2010 2:09 pm 
    Connoisseur of the Godawful
    User avatar
     

    Joined:Tue Mar 01, 2005 9:00 am
    Posts:456
    ICQ:286315965
    Website:http://rabidtinker.mine.nu/
    Yahoo Messenger:alistair_lynn
    AOL:Agent_Vast@mac.com
    Location:127.0.0.1
    Simplest way would be to simply shove your data in a std::string and then write it out to a file with .data() and .length().

    _________________
    Alastair Lynn / Alumnus / Onlink Team


    Top
    Offline  
    Display posts from previous: Sort by 
    Post new topic Reply to topic

      All times are UTC-05:00


      Who is online

      Users browsing this forum: No registered users and 1 guest


      You cannot post new topics in this forum
      You cannot reply to topics in this forum
      You cannot edit your posts in this forum
      You cannot delete your posts in this forum
      You cannot post attachments in this forum

      Search for:
      Jump to:  
      cron
      Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
      Theme created by Miah with assistance from hyprnova