const size_t maxCompressedSize = ZSTD_compressBound(srcSize) + (maxNbBlocks * 1024); /* add some room for safety */
void* const compressedBuffer = malloc(maxCompressedSize);
void* const resultBuffer = malloc(srcSize);
+ ZSTD_CCtx* refCtx = ZSTD_createCCtx();
ZSTD_CCtx* ctx = ZSTD_createCCtx();
ZSTD_DCtx* dctx = ZSTD_createDCtx();
U64 crcOrig = XXH64(srcBuffer, srcSize, 0);
if (strlen(displayName)>17) displayName += strlen(displayName)-17; /* can only display 17 characters */
/* Memory allocation & restrictions */
- if (!compressedBuffer || !resultBuffer || !blockTable || !ctx || !dctx)
+ if (!compressedBuffer || !resultBuffer || !blockTable || !refCtx || !ctx || !dctx)
EXM_THROW(31, "not enough memory");
/* Init blockTable data */
milliTime = BMK_GetMilliStart();
while (BMK_GetMilliSpan(milliTime) < TIMELOOP)
{
+ ZSTD_compressBegin_advanced(refCtx, ZSTD_getParams(cLevel, dictBufferSize+blockSize));
+ ZSTD_compress_insertDictionary(refCtx, dictBuffer, dictBufferSize);
for (blockNb=0; blockNb<nbBlocks; blockNb++)
- blockTable[blockNb].cSize = ZSTD_compress_usingDict(ctx,
+ {
+ ZSTD_duplicateCCtx(ctx, refCtx);
+ size_t rSize = ZSTD_compressContinue(ctx,
+ blockTable[blockNb].cPtr, blockTable[blockNb].cRoom,
+ blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize);
+ if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_compressContinue() failed : %s", ZSTD_getErrorName(rSize));
+ blockTable[blockNb].cSize = rSize;
+ rSize = ZSTD_compressEnd(ctx,
+ blockTable[blockNb].cPtr + rSize,
+ blockTable[blockNb].cRoom - rSize);
+ if (ZSTD_isError(rSize)) EXM_THROW(2, "ZSTD_compressEnd() failed : %s", ZSTD_getErrorName(rSize));
+ blockTable[blockNb].cSize += rSize;
+ }
+ /*blockTable[blockNb].cSize = ZSTD_compress_usingDict(ctx,
blockTable[blockNb].cPtr, blockTable[blockNb].cRoom,
blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize,
dictBuffer, dictBufferSize,
- cLevel);
+ cLevel);*/
nbLoops++;
}
milliTime = BMK_GetMilliSpan(milliTime);
/* clean up */
free(compressedBuffer);
free(resultBuffer);
+ ZSTD_freeCCtx(refCtx);
ZSTD_freeCCtx(ctx);
ZSTD_freeDCtx(dctx);
return 0;