-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Labels
Description
Hello, thanks for the great library!
We wanted to verify we aren't running into any UB here.
We are using an ObjectPool of compressors like in this comment #31 (comment) with a small tweak that we're using a custom PoolObjectPolicy and passing in a dictionary:
new DefaultObjectPool<Compressor>(
new CustomPolicy(
new CompressionOptions(dictionaryBytes)));
We then call Wrap multiple times serially on the same compressor.
The question is whether there's any sort of reset on the context necessary? Following all the Wrap calls, this eventually calls:
ExternMethods.ZSTD_compress_usingCDict(this.cctx, dst, (UIntPtr) checked ((ulong) dst.Length), src, (UIntPtr) checked ((ulong) src.Length), this.Options.Cdict))).EnsureZstdSuccess()));
The docs seem to say you can reuse a ZSTD_CDict* with no issue in the bulk processing dictionary API + in the beginning it says we can reuse a context multiple times:
When compressing many times,
it is recommended to allocate a context just once,
and re-use it for each successive compression operation.
This will make workload friendlier for system's memory.
Note : re-using context is just a speed / resource optimization.
It doesn't change the compression ratio, which remains identical.
Note 2 : In multi-threaded environments,
use one different context per thread for parallel execution.
typedef struct ZSTD_CCtx_s ZSTD_CCtx;
ZSTD_CCtx* ZSTD_createCCtx(void);
size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /* accept NULL pointer */
Just making sure this is an accurate understanding of how the lib is meant to be used?