diff --git a/doc/zstd_manual.html b/doc/zstd_manual.html index 4397faf7..2cd4f78c 100644 --- a/doc/zstd_manual.html +++ b/doc/zstd_manual.html @@ -414,14 +414,18 @@ size_t ZSTD_estimateDCtxSize(void); of a future {D,C}Ctx, before its creation. The objective is to guide decision before allocation. ZSTD_estimateCCtxSize() will consider src size to be arbitrarily "large". - If srcSize is known to be small, ZSTD_estimateCCtxSize_advanced() will provide a better (smaller) estimation. + If srcSize is known to be small, ZSTD_estimateCCtxSize_advanced() can provide a tighter estimation. ZSTD_estimateCCtxSize_advanced() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. Note : CCtx estimation is only correct for single-threaded compression


-
size_t ZSTD_estimateCStreamSize(ZSTD_compressionParameters cParams);
+
size_t ZSTD_estimateCStreamSize(int compressionLevel);
+size_t ZSTD_estimateCStreamSize_advanced(ZSTD_compressionParameters cParams);
 size_t ZSTD_estimateDStreamSize(ZSTD_frameHeader fHeader);
-

Note : if streaming is init with function ZSTD_init?Stream_usingDict(), +

ZSTD_estimateCStreamSize() will consider src size to be arbitrarily "large". + If srcSize is known to be small, ZSTD_estimateCStreamSize_advanced() can provide a tighter estimation. + ZSTD_estimateCStreamSize_advanced() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. + Note : if streaming is init with function ZSTD_init?Stream_usingDict(), an internal ?Dict will be created, which size is not estimated here. In this case, get total size by adding ZSTD_estimate?DictSize


diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 1bf67692..f74f4d8a 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -564,7 +564,7 @@ size_t ZSTD_estimateCCtxSize(int compressionLevel) return ZSTD_estimateCCtxSize_advanced(cParams); } -size_t ZSTD_estimateCStreamSize(ZSTD_compressionParameters cParams) +size_t ZSTD_estimateCStreamSize_advanced(ZSTD_compressionParameters cParams) { size_t const CCtxSize = ZSTD_estimateCCtxSize_advanced(cParams); size_t const blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << cParams.windowLog); @@ -575,6 +575,11 @@ size_t ZSTD_estimateCStreamSize(ZSTD_compressionParameters cParams) return CCtxSize + streamingSize; } +size_t ZSTD_estimateCStreamSize(int compressionLevel) { + ZSTD_compressionParameters const cParams = ZSTD_getCParams(compressionLevel, 0, 0); + return ZSTD_estimateCStreamSize_advanced(cParams); +} + static U32 ZSTD_equivalentParams(ZSTD_compressionParameters cParams1, ZSTD_compressionParameters cParams2) diff --git a/lib/zstd.h b/lib/zstd.h index 65932088..9c6932fb 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -498,7 +498,7 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); * of a future {D,C}Ctx, before its creation. * The objective is to guide decision before allocation. * ZSTD_estimateCCtxSize() will consider src size to be arbitrarily "large". - * If srcSize is known to be small, ZSTD_estimateCCtxSize_advanced() will provide a better (smaller) estimation. + * If srcSize is known to be small, ZSTD_estimateCCtxSize_advanced() can provide a tighter estimation. * ZSTD_estimateCCtxSize_advanced() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. * Note : CCtx estimation is only correct for single-threaded compression */ ZSTDLIB_API size_t ZSTD_estimateCCtxSize(int compressionLevel); @@ -506,10 +506,14 @@ ZSTDLIB_API size_t ZSTD_estimateCCtxSize_advanced(ZSTD_compressionParameters cPa ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void); /*! ZSTD_estimate?StreamSize() : + * ZSTD_estimateCStreamSize() will consider src size to be arbitrarily "large". + * If srcSize is known to be small, ZSTD_estimateCStreamSize_advanced() can provide a tighter estimation. + * ZSTD_estimateCStreamSize_advanced() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. * Note : if streaming is init with function ZSTD_init?Stream_usingDict(), * an internal ?Dict will be created, which size is not estimated here. * In this case, get total size by adding ZSTD_estimate?DictSize */ -ZSTDLIB_API size_t ZSTD_estimateCStreamSize(ZSTD_compressionParameters cParams); +ZSTDLIB_API size_t ZSTD_estimateCStreamSize(int compressionLevel); +ZSTDLIB_API size_t ZSTD_estimateCStreamSize_advanced(ZSTD_compressionParameters cParams); ZSTDLIB_API size_t ZSTD_estimateDStreamSize(ZSTD_frameHeader fHeader); /*! ZSTD_estimate?DictSize() : diff --git a/tests/fuzzer.c b/tests/fuzzer.c index a3a56d9d..7d33955f 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -193,8 +193,7 @@ static int basicUnitTests(U32 seed, double compressibility) /* Static CCtx tests */ #define STATIC_CCTX_LEVEL 3 DISPLAYLEVEL(4, "test%3i : create static CCtx for level %u :", testNb++, STATIC_CCTX_LEVEL); - { ZSTD_compressionParameters const cParams = ZSTD_getCParams(STATIC_CCTX_LEVEL, 0, 0); - size_t const staticCCtxSize = ZSTD_estimateCStreamSize(cParams); + { size_t const staticCCtxSize = ZSTD_estimateCStreamSize(STATIC_CCTX_LEVEL); void* const staticCCtxBuffer = malloc(staticCCtxSize); size_t const staticDCtxSize = ZSTD_estimateDCtxSize(); void* const staticDCtxBuffer = malloc(staticDCtxSize); diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index 0e14fd23..7c60b706 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -210,7 +210,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo /* context size functions */ DISPLAYLEVEL(3, "test%3i : estimate CStream size : ", testNb++); { ZSTD_compressionParameters const cParams = ZSTD_getCParams(1, CNBufferSize, dictSize); - size_t const s = ZSTD_estimateCStreamSize(cParams) + size_t const s = ZSTD_estimateCStreamSize_advanced(cParams) /* uses ZSTD_initCStream_usingDict() */ + ZSTD_estimateCDictSize(cParams, dictSize, 0); if (ZSTD_isError(s)) goto _output_error;