pub unsafe extern "C" fn ZSTD_estimateCCtxSize(
    maxCompressionLevel: c_int
) -> usize
Expand description

ZSTD_estimate*() : These functions make it possible to estimate memory usage of a future {D,C}Ctx, before its creation. This is useful in combination with ZSTD_initStatic(), which makes it possible to employ a static buffer for ZSTD_CCtx* state.

ZSTD_estimateCCtxSize() will provide a memory budget large enough to compress data of any size using one-shot compression ZSTD_compressCCtx() or ZSTD_compress2() associated with any compression level up to max specified one. The estimate will assume the input may be arbitrarily large, which is the worst case.

Note that the size estimation is specific for one-shot compression, it is not valid for streaming (see ZSTD_estimateCStreamSize*()) nor other potential ways of using a ZSTD_CCtx* state.

When srcSize can be bound by a known and rather “small” value, this knowledge can be used to provide a tighter budget estimation because the ZSTD_CCtx* state will need less memory for small inputs. This tighter estimation can be provided by employing more advanced functions ZSTD_estimateCCtxSize_usingCParams(), which can be used in tandem with ZSTD_getCParams(), and ZSTD_estimateCCtxSize_usingCCtxParams(), which can be used in tandem with ZSTD_CCtxParams_setParameter(). Both can be used to estimate memory using custom compression parameters and arbitrary srcSize limits.

Note : only single-threaded compression is supported. ZSTD_estimateCCtxSize_usingCCtxParams() will return an error code if ZSTD_c_nbWorkers is >= 1.