Reputation: 666
I have a Qt C++ program that process some data in a loop.
It appends each data processing result to the end of a text file. Data processing operations are placed in a loop, so the program can produce more that 800 results in a few seconds and write them one by one (i.e. separately).
I thought that so much I/O operations are not very good for computer's hard drive, so I organized an array where I store data processing results, and when array length is more than 200, the program appends it to file and clean, than the array becomes more that 200 again, and so on.
But I don't know exactly - is it really needed? Maybe it is just a waste of RAM and I should append data to text file without those arrays (buffers)? After all, the program writes the same amount of data, independently in which way it does.
Upvotes: 2
Views: 255
Reputation: 129
Generally speaking, since c++ mechanism is providing with buffered io, you can change it as you like. In you context, "800 results" you referred does not tell the exact size of your output data. So You may be overskilled. F.Y.I, the function ios::rdbuf() will get a pointer to a streambuf object that represents the internal buffer for the stream. Then You can call streambuf::pubsetbuf(char * s, streamsize n) to set a new internal buffer with a given size. You can also find detail from http://en.cppreference.com/w/cpp/io/basic_ios/rdbuf.
Upvotes: 1