我有一个代码工作,但我对结果并不完全满意,所以我想我可以在这里问一些问题。
这是我的两个功能:
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) 的最后一个参数,但它并没有提高性能,甚至一点也没有。还有其他事情要做吗?
- 如果您有任何提示,请随时告诉我。
谢谢。