*/
static size_t ZSTD_workspace_align(size_t size, size_t align) {
return size + align - 1 - ((size - 1) & (align - 1));
- // return size + 3 - ((size - 1) & 3);
}
static void* ZSTD_workspace_reserve(ZSTD_CCtx_workspace* ws, size_t bytes, ZSTD_workspace_alloc_phase_e phase) {
return 0;
}
+/**
+ * Invalidates table allocations.
+ * All other allocations remain valid.
+ */
static void ZSTD_workspace_clear_tables(ZSTD_CCtx_workspace* ws) {
ws->tableEnd = ws->objectEnd;
}
+/**
+ * Invalidates all buffer, aligned, and table allocations.
+ * Object allocations remain valid.
+ */
static void ZSTD_workspace_clear(ZSTD_CCtx_workspace* ws) {
DEBUGLOG(3, "wksp: clearing!");
ZSTD_workspace_bump_oversized_duration(ws);
* are divided into the following categories:
*
* - Static objects: this is optionally the enclosing ZSTD_CCtx or ZSTD_CDict,
- * so that literally everything fits in a single buffer.
+ * so that literally everything fits in a single buffer. Note: if present,
+ * this must be the first object in the workspace, since ZSTD_free{CCtx,
+ * CDict}() rely on a pointer comparison to see whether one or two frees are
+ * required.
*
* - Fixed size objects: these are fixed-size, fixed-count objects that are
* nonetheless "dynamically" allocated in the workspace so that we can
* uint32_t arrays, all of whose values are between 0 and (nextSrc - base).
* Their sizes depend on the cparams.
*
+ * - Aligned: these buffers are used for various purposes that don't require
+ * any initialization before they're used.
+ *
* - Uninitialized memory: these buffers are used for various purposes that
* don't require any initialization before they're used. This means they can
* be moved around at no cost for a new compression.
- * - I/O Buffers
*
- * [workspace, workspace + workspaceSize)
- * []
+ * Allocating Memory:
+ *
+ * The various types of objects must be allocated in order, so they can be
+ * correctly packed into the workspace buffer. That order is:
+ *
+ * 1. Objects
+ * 2. Buffers
+ * 3. Aligned
+ * 4. Tables
*/
typedef struct {
void* workspace;