出力ファイルを圧縮するために gzip_compressor() を使用しました。この目的のために、2 つの方法を使用しました。共通部分は
std::ofstream traceOut;
traceOut.open("log.gz", std::ios_base::out);
struct traceRec {
traceRec(uint64_t c) : cycle(c) {};
uint64_t cycle;
};
void writeTrace(traceRec &rec)
{
boost::iostreams::filtering_ostream o;
o.push(boost::iostreams::gzip_compressor());
o.push(traceOut);
// METHOD 1 OR 2
}
方法 1
私が使う
o.write(reinterpret_cast<const char*>(&rec.cycle), sizeof(rec.cycle));
今回の実装でファイルサイズはなんと380K!!
方法 2
私が使う
traceOut << rec.cycle << std::endl;
今回の実装でファイルサイズは78K!!
では、なぜサイズが異なるのでしょうか?? もう1つのことは、gzip_compressorを使用せずにファイルに直接書き込む場合です
std::ofstream traceOut;
traceOut.open("log.gz", std::ios_base::out);
...
traceOut << rec.cycle << std::endl;
ファイルサイズは78Kになります。
したがって、次の 2 つの問題があります。
1-使用しgzip_compressor
ても使用しなくてもファイルサイズには影響しません
2-使用するためのさまざまな実装gzip_compressor
により、さまざまなファイルサイズが生成されます
それについて何か考えはありますか?