gzip_compressor()를 사용하여 압축 된 출력 파일을 만들었습니다. 나는이 목적을 위해 두 가지 방법을 사용했다. 공통 부분은 내가이 구현으로 gzip_compressor를 사용하면 다른 파일 크기가 생성됩니다.
o.write(reinterpret_cast<const char*>(&rec.cycle), sizeof(rec.cycle));
를 사용
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
이며, 파일 크기는 380K입니다!
방법 2
내가이 구현으로
traceOut << rec.cycle << std::endl;
을 사용하여 파일 크기는 78K입니다!
왜 크기가 다른가요? 또 다른 것은 gzip_compressor를 사용하지 않고 파일에 직접 쓸 때
std::ofstream traceOut;
traceOut.open("log.gz", std::ios_base::out);
...
traceOut << rec.cycle << std::endl;
파일 크기는 78K입니다.
그래서이 두 가지 문제가 있습니다
1 사용 또는 gzip_compressor
를 사용하지 않는 것이
2 개 다른 구현 gzip_compressor
수율 다른 파일을 사용하는 파일 크기에 영향을주지 않습니다
그것에 대해 어떤 생각 크기 ?
큰 출력의 경우 쓰기 방법이 더 좋습니다. 압축기를 사용할 때와 사용하지 않을 때의 크기는 어떻습니까? – mahmood
값을 저장하는 데 필요한 코드 크기의 문제입니다. "13"은 2 바이트가 필요하고 0x000000000000000D는 8 (압축 전)이 필요합니다. 반면에 "2434533376"을 저장하려면 10 바이트가 필요하지만 여전히 바이너리 형식으로 8이 필요합니다. – xryl669
압축기 사용에 관해서는 "filtering_streambuf