Ferrous Moon
http://www.ferrousmoon.com:80/forums/

How to write data to a "file" in memory
http://www.ferrousmoon.com:80/forums/viewtopic.php?f=45&t=2018
Page 1 of 1

Author:  Darkknight512 [Fri May 14, 2010 10:43 pm ]
Post subject:  How to write data to a "file" in memory

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.

Author:  ChaosR [Sat May 15, 2010 11:41 am ]
Post subject:  Re: How to write data to a "file" in memory

Code:
while(!done) { buffer = ""; for(1 to 1000) { data = do_stuff() append(buffer, data) } write(file, buffer) }
Pseudocode hurray!

Author:  prophile [Sat May 15, 2010 2:09 pm ]
Post subject:  Re: How to write data to a "file" in memory

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().

Page 1 of 1 All times are UTC-05:00
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/