コードは機能していますが、結果に完全に満足しているわけではないので、ここでいくつか質問できると思いました。
ここに私の2つの機能があります:
void compress(string nameSrc, string nameDst){
ifstream input;
input.open(nameSrc,fstream::in | fstream::binary);
size_t propsSize = LZMA_PROPS_SIZE;
size_t srcLen = getLength(input);
size_t dstLen = srcLen; //??? no idea how to know to right value here
unsigned char* src = new unsigned char[srcLen];
unsigned char* dst = new unsigned char[dstLen + propsSize];
input.read((char*)src, srcLen);
int res = LzmaCompress(
&dst[LZMA_PROPS_SIZE], &dstLen,
src, srcLen,
dst, &propsSize,
-1, 0, -1, -1, -1, -1, -1);
delete [] src;
input.close();
ofstream output(nameDst, ios::binary);
output.write((char*)dst, dstLen + propsSize);
delete [] dst;
}
と :
void unCompress(string nameSrc, string nameDst){
ifstream input;
input.open(nameSrc,fstream::in | fstream::binary);
size_t srcLen = getLength(input);
size_t dstLen = srcLen*5; //??? no idea how to know to right value here
unsigned char* src = new unsigned char[srcLen];
unsigned char* dst = new unsigned char[dstLen];
input.read((char*)src,srcLen);
int res = LzmaUncompress(dst,&dstLen,&src[LZMA_PROPS_SIZE],&srcLen, src, LZMA_PROPS_SIZE);
delete [] src;
input.close();
ofstream output(nameDst, ios::binary);
output.write((char*)dst, dstLen);
delete [] dst;
}
- 両方の関数で、 dstLen に入れる値をどのように知る必要がありますか? 大量のメモリを無駄に割り当てたくありません。
- char* にキャストしなければならないのは悪いことですか? 本当に unsigned char を使用する必要がありますか?
- LzmaCompress の最後の引数 (numThreads) を変更してみましたが、パフォーマンスは少しも改善されませんでした。他に何かすることはありますか?
- ヒントがあれば、遠慮なく教えてください。
ありがとう。