Archived

This topic is now archived and is closed to further replies.

psykr

settings saver

Recommended Posts

I have written a console program that reads strings from an INI file. It then takes user input to change the values of the strings. How do I change the values in the INI file? Do I have to read the entire thing to memory, then write it all back? Or is there some more efficient way to do it?

Share this post


Link to post
Share on other sites
The most efficient way to do this is just reading everything to memory, and than rewriting the entire file.
If it was a binary file it might be faster to just seek to the position of the data you need to rewrite, and overwrite only the bytes you want to change, but with a text file it''s not.
If you want to do that with a text file, where the length of each item is variable, you would need to read through the entire file anyway to find the position where your data needs to be stored, than store the data, and than you maybe need to move everything that''s behind the data you just stored because the length of the new item is longer/shorter than the old item. As you can see this is a lot more work, than simply reading everything to memory, and rewriting everything.

My Site

Share this post


Link to post
Share on other sites