Dear all,

I have some numerical data in my code that I'm saving to a file. My code loops thousands of times generating a set of this data in each loop step. The data is reused within the same step but there is no need to save it to the next one. Currently I'm using the serialization library to write all the data to a binary file (using the optimization for contiguous arrays) and then read it. I thought (maybe naively) I could increase performance keeping the data in memory instead of write/read to disk. I came across this post http://lists.boost.org/boost-users/2008/05/36235.php where how to serialize into/from a memory buffer using boost::iostreams is explained. However I found that using the solution in the post is way slower than write/read to disk. In fact modifying the code in the post to use std::ofstream and std::ifstream open with the std::ios::binary flag makes the code 5 times faster.

Am I missing something or is it right that the iostream solution is slower ?.  (I understand that sometimes you don't have the option to write to a file, but is this the fastest way to use a memory buffer ?)

Thanks in advance,

Ivan