file - Simultaneously writing out an array while casting efficiently -


i have array of long doubles. want write out array of doubles, don't want create double array first (i don't have memory), , i'm worried performance.

my (naive) solution:

 file.open(filename.c_str(), std::ios::binary | std::ios::out);  if (file.is_open())  {     (auto& : out)     {         t2 ni = static_cast<t2>(i);         file.write(reinterpret_cast<const char*>(&ni), static_cast<size_t>(sizeof(t2)));     }     file.close();  } 

however, arrays i'm attempting write out, calling file.write 630,000,000 times (and since file.write creates sentry object on each instantiation, expensive). there more efficient way this?


Comments

Popular posts from this blog

c - ALSA programming: how to stop immediately -

c++ - How to add Crypto++ library to Qt project -