N
nitroamos
i'm working on improving the IO for the software project i'm working on
to do two extra things. first, i'm going to add HDF5 functionality, and
second, add the ability to write binary output. the software is
computational science where a lot of stuff is going to be calculated
and written to a file. e.g. could be up to gigabytes of data.
my question has to do with the latter -- and how often i need to call
"flush" on the stream. what I want the software to do is store up
several entries in memory and then dump several megabytes (or some
optimal number) all at once since this is the optimal setting that
makes the most sense to me.
so how does the buffering in a fstream, (or a filebuf) work?
specifically, if i just keep doing "write" commands, will it dump the
entire buffer when the buffer gets full? or will it only dump enough of
the buffer to make room for each "write"? can I rely on the standard
c++ libraries written for each machine to choose an optimal buffering
scheme and buffer size? it seems like at least some of these details
are implementation dependent... but i don't know which.
here's a reference:
http://www.cplusplus.com/ref/iostream/filebuf/
but nobody really discusses this issue that I can find any reference
to.
basically i'm wondering if i need to add the following to my code:
1) choose an optimal buffer size somehow
2) create and give it to the filebuf via pubsetbuf
3) figure out how many entries would fill my buffer
then in the process of the calculation
when I know the buffer is full, flush
so my question is, how much can i rely on the standard IO library to
handle this for me? i assume that each company who writes an IO library
for their machine would know the best way to handle it, but i just want
to be sure that none of their choices affect me.
thanks!
Amos.
nitroamos a t y a h o o
to do two extra things. first, i'm going to add HDF5 functionality, and
second, add the ability to write binary output. the software is
computational science where a lot of stuff is going to be calculated
and written to a file. e.g. could be up to gigabytes of data.
my question has to do with the latter -- and how often i need to call
"flush" on the stream. what I want the software to do is store up
several entries in memory and then dump several megabytes (or some
optimal number) all at once since this is the optimal setting that
makes the most sense to me.
so how does the buffering in a fstream, (or a filebuf) work?
specifically, if i just keep doing "write" commands, will it dump the
entire buffer when the buffer gets full? or will it only dump enough of
the buffer to make room for each "write"? can I rely on the standard
c++ libraries written for each machine to choose an optimal buffering
scheme and buffer size? it seems like at least some of these details
are implementation dependent... but i don't know which.
here's a reference:
http://www.cplusplus.com/ref/iostream/filebuf/
but nobody really discusses this issue that I can find any reference
to.
basically i'm wondering if i need to add the following to my code:
1) choose an optimal buffer size somehow
2) create and give it to the filebuf via pubsetbuf
3) figure out how many entries would fill my buffer
then in the process of the calculation
when I know the buffer is full, flush
so my question is, how much can i rely on the standard IO library to
handle this for me? i assume that each company who writes an IO library
for their machine would know the best way to handle it, but i just want
to be sure that none of their choices affect me.
thanks!
Amos.
nitroamos a t y a h o o