9#ifndef BROTLI_ENC_MEMORY_H_
10#define BROTLI_ENC_MEMORY_H_
16#include "../common/platform.h"
18#if defined(__cplusplus) || defined(c_plusplus)
22#if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \
23 !defined(BROTLI_ENCODER_EXIT_ON_OOM)
24#define BROTLI_ENCODER_EXIT_ON_OOM
27#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
28#if defined(BROTLI_EXPERIMENTAL)
29#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS (48*1024)
31#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 256
34#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS 0
41#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
43 size_t perm_allocated;
46 void* pointers[BROTLI_ENCODER_MEMORY_MANAGER_SLOTS];
50BROTLI_INTERNAL
void BrotliInitMemoryManager(
54BROTLI_INTERNAL
void* BrotliAllocate(
MemoryManager* m,
size_t n);
55#define BROTLI_ALLOC(M, T, N) \
56 ((N) > 0 ? ((T*)BrotliAllocate((M), (N) * sizeof(T))) : NULL)
59#define BROTLI_FREE(M, P) { \
60 BrotliFree((M), (P)); \
64#if defined(BROTLI_ENCODER_EXIT_ON_OOM)
65#define BROTLI_IS_OOM(M) (!!0)
67#define BROTLI_IS_OOM(M) (!!(M)->is_oom)
76#if defined(__clang_analyzer__) && !defined(BROTLI_ENCODER_EXIT_ON_OOM)
77#define BROTLI_IS_NULL(A) ((A) == nullptr)
79#define BROTLI_IS_NULL(A) (!!0)
82BROTLI_INTERNAL
void BrotliWipeOutMemoryManager(
MemoryManager* m);
92#define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) { \
94 size_t _new_size = (C == 0) ? (R) : C; \
96 while (_new_size < (R)) _new_size *= 2; \
97 new_array = BROTLI_ALLOC((M), T, _new_size); \
98 if (!BROTLI_IS_OOM(M) && !BROTLI_IS_NULL(new_array) && C != 0) \
99 memcpy(new_array, A, C * sizeof(T)); \
100 BROTLI_FREE((M), A); \
115#define BROTLI_ENSURE_CAPACITY_APPEND(M, T, A, C, S, V) { \
117 BROTLI_ENSURE_CAPACITY(M, T, A, C, S); \
123BROTLI_INTERNAL
void* BrotliBootstrapAlloc(
size_t size,
125BROTLI_INTERNAL
void BrotliBootstrapFree(
void* address,
MemoryManager* m);
127#if defined(__cplusplus) || defined(c_plusplus)
Common types used in decoder and encoder API.
void *(* brotli_alloc_func)(void *opaque, size_t size)
Allocating function pointer type.
Definition: types.h:71
void(* brotli_free_func)(void *opaque, void *address)
Deallocating function pointer type.
Definition: types.h:81
#define BROTLI_BOOL
A portable bool replacement.
Definition: types.h:49