Skip to content

Commit 292eeb6

Browse files
committed
api doc : grouped all ZSTD_create*_advanced() functions together
in a new "custom memory allocator" paragraph which is itself part of "memory management" category. This makes it simpler to see the relation between the type and its usages.
1 parent 3ea1563 commit 292eeb6

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

lib/zstd.h

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,6 @@ typedef enum {
442442
} ZSTD_dictLoadMethod_e;
443443

444444

445-
/*--- Custom memory allocation functions ---*/
446-
typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
447-
typedef void (*ZSTD_freeFunction) (void* opaque, void* address);
448-
typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
449-
/* use this constant to defer to stdlib's functions */
450-
static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL };
451-
452445

453446
/***************************************
454447
* Frame size functions
@@ -585,29 +578,43 @@ ZSTDLIB_API ZSTD_DDict* ZSTD_initStaticDDict(void* workspace, size_t workspaceSi
585578
const void* dict, size_t dictSize,
586579
ZSTD_dictLoadMethod_e dictLoadMethod);
587580

581+
/*! Custom memory allocation :
582+
* These prototypes make it possible to pass your own allocation/free functions.
583+
* ZSTD_customMem is provided at creation time, using ZSTD_create*_advanced() variants listed below.
584+
* All allocation/free operations will be completed using these custom variants instead of regular <stdlib.h> ones.
585+
*/
586+
typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size);
587+
typedef void (*ZSTD_freeFunction) (void* opaque, void* address);
588+
typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem;
589+
static ZSTD_customMem const ZSTD_defaultCMem = { NULL, NULL, NULL }; /**< this constant defers to stdlib's functions */
590+
591+
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
592+
ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
593+
ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem);
594+
ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem);
595+
596+
ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize,
597+
ZSTD_dictLoadMethod_e dictLoadMethod,
598+
ZSTD_dictMode_e dictMode,
599+
ZSTD_compressionParameters cParams,
600+
ZSTD_customMem customMem);
601+
602+
ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize,
603+
ZSTD_dictLoadMethod_e dictLoadMethod,
604+
ZSTD_customMem customMem);
605+
588606

589607

590608
/***************************************
591609
* Advanced compression functions
592610
***************************************/
593-
/*! ZSTD_createCCtx_advanced() :
594-
* Create a ZSTD compression context using external alloc and free functions */
595-
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem);
596611

597612
/*! ZSTD_createCDict_byReference() :
598613
* Create a digested dictionary for compression
599614
* Dictionary content is simply referenced, and therefore stays in dictBuffer.
600615
* It is important that dictBuffer outlives CDict, it must remain read accessible throughout the lifetime of CDict */
601616
ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_byReference(const void* dictBuffer, size_t dictSize, int compressionLevel);
602617

603-
/*! ZSTD_createCDict_advanced() :
604-
* Create a ZSTD_CDict using external alloc and free, and customized compression parameters */
605-
ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize,
606-
ZSTD_dictLoadMethod_e dictLoadMethod,
607-
ZSTD_dictMode_e dictMode,
608-
ZSTD_compressionParameters cParams,
609-
ZSTD_customMem customMem);
610-
611618
/*! ZSTD_getCParams() :
612619
* @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize.
613620
* `estimatedSrcSize` value is optional, select 0 if not known */
@@ -652,22 +659,13 @@ ZSTDLIB_API size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx,
652659
* Note 3 : Skippable Frame Identifiers are considered valid. */
653660
ZSTDLIB_API unsigned ZSTD_isFrame(const void* buffer, size_t size);
654661

655-
/*! ZSTD_createDCtx_advanced() :
656-
* Create a ZSTD decompression context using external alloc and free functions */
657-
ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem);
658-
659662
/*! ZSTD_createDDict_byReference() :
660663
* Create a digested dictionary, ready to start decompression operation without startup delay.
661664
* Dictionary content is referenced, and therefore stays in dictBuffer.
662665
* It is important that dictBuffer outlives DDict,
663666
* it must remain read accessible throughout the lifetime of DDict */
664667
ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize);
665668

666-
/*! ZSTD_createDDict_advanced() :
667-
* Create a ZSTD_DDict using external alloc and free, optionally by reference */
668-
ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize,
669-
ZSTD_dictLoadMethod_e dictLoadMethod,
670-
ZSTD_customMem customMem);
671669

672670
/*! ZSTD_getDictID_fromDict() :
673671
* Provides the dictID stored within dictionary.
@@ -699,7 +697,6 @@ ZSTDLIB_API unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize);
699697
********************************************************************/
700698

701699
/*===== Advanced Streaming compression functions =====*/
702-
ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem);
703700
ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize); /**< pledgedSrcSize must be correct. If it is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN. Note that, for compatibility with older programs, "0" also disables frame content size field. It may be enabled in the future. */
704701
ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); /**< creates of an internal CDict (incompatible with static CCtx), except if dict == NULL or dictSize < 8, in which case no dict is used. Note: dict is loaded with ZSTD_dm_auto (treated as a full zstd dictionary if it begins with ZSTD_MAGIC_DICTIONARY, else as raw content) and ZSTD_dlm_byCopy.*/
705702
ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize,
@@ -720,7 +717,6 @@ ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledg
720717

721718

722719
/*===== Advanced Streaming decompression functions =====*/
723-
ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem);
724720
typedef enum { DStream_p_maxWindowSize } ZSTD_DStreamParameter_e;
725721
ZSTDLIB_API size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, unsigned paramValue); /* obsolete : this API will be removed in a future version */
726722
ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); /**< note: no dictionary will be used if dict == NULL or dictSize < 8 */
@@ -891,8 +887,7 @@ ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx);
891887
*
892888
* This API is intended to replace all others experimental API.
893889
* It can basically do all other use cases, and even new ones.
894-
* In constrast with _advanced() variants, it stands a reasonable chance to become "stable",
895-
* after a good testing period.
890+
* It stands a reasonable chance to become "stable", after a good testing period.
896891
*/
897892

898893
/* note on naming convention :
@@ -1137,7 +1132,7 @@ ZSTDLIB_API size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
11371132
* All parameters are back to default values.
11381133
* It's possible to modify compression parameters after a reset.
11391134
*/
1140-
ZSTDLIB_API void ZSTD_CCtx_reset(ZSTD_CCtx* cctx); /* Not ready yet ! */
1135+
ZSTDLIB_API void ZSTD_CCtx_reset(ZSTD_CCtx* cctx);
11411136

11421137

11431138
/*! ZSTD_compress_generic_simpleArgs() :
@@ -1354,7 +1349,7 @@ ZSTDLIB_API void ZSTD_DCtx_reset(ZSTD_DCtx* dctx);
13541349
ZSTDLIB_API size_t ZSTD_getBlockSize (const ZSTD_CCtx* cctx);
13551350
ZSTDLIB_API size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
13561351
ZSTDLIB_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
1357-
ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert uncompressed block into `dctx` history. Useful for multi-blocks decompression */
1352+
ZSTDLIB_API size_t ZSTD_insertBlock (ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert uncompressed block into `dctx` history. Useful for multi-blocks decompression. */
13581353

13591354

13601355
#endif /* ZSTD_H_ZSTD_STATIC_LINKING_ONLY */

0 commit comments

Comments
 (0)