1

コードは機能していますが、結果に完全に満足しているわけではないので、ここでいくつか質問できると思いました。

ここに私の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;
}

  1. 両方の関数で、 dstLen に入れる値をどのように知る必要がありますか? 大量のメモリを無駄に割り当てたくありません。
  2. char* にキャストしなければならないのは悪いことですか? 本当に unsigned char を使用する必要がありますか?
  3. LzmaCompress の最後の引数 (numThreads) を変更してみましたが、パフォーマンスは少しも改善されませんでした。他に何かすることはありますか?
  4. ヒントがあれば、遠慮なく教えてください。

ありがとう。

4

2 に答える 2

1

次の関数を使用して宛先サイズを取得します。

INT32
EFIAPI
LzmaGetInfo(
CONST VOID  *Source,
UINT32      SourceSize,
UINT32      *DestinationSize
)
{
    UInt64  DecodedSize;

    ASSERT(SourceSize >= LZMA_HEADER_SIZE); (void)SourceSize;

    DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source);

    *DestinationSize = (UINT32)DecodedSize;
    return ERR_SUCCESS;
}
于 2014-12-07T12:08:18.320 に答える