RAMを大量に消費するプログラムに対してディスクI/O操作を実行したい。私は倍精度の行列を使用し、バイトとしてディスクに書き込むのが最速の方法だと思います(倍精度を維持する必要があります)。
移植性でそれを行う方法は?
私はこのコード(ここ)を見つけましたが、作者はそれが移植性がないと言っています...
#include <iostream>
#include <fstream>
int main()
{
using namespace std;
ofstream ofs( "atest.txt", ios::binary );
if ( ofs ) {
double pi = 3.14;
ofs.write( reinterpret_cast<char*>( &pi ), sizeof pi );
// Close the file to unlock it
ofs.close();
// Use a new object so we don't have to worry
// about error states in the old object
ifstream ifs( "atest.txt", ios::binary );
double read;
if ( ifs ) {
ifs.read( reinterpret_cast<char*>( &read ), sizeof read );
cout << read << '\n';
}
}
return 0;
}