9#ifndef BROTLI_ENC_MEMORY_H_
10#define BROTLI_ENC_MEMORY_H_
14#include <brotli/types.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;
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)
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); \
127#if defined(__cplusplus) || defined(c_plusplus)
#define BROTLI_ENCODER_MEMORY_MANAGER_SLOTS
Definition memory.h:34
BROTLI_INTERNAL void * BrotliAllocate(MemoryManager *m, size_t n)
Definition memory.c:52
BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager *m)
Definition memory.c:62
struct MemoryManager MemoryManager
BROTLI_INTERNAL void BrotliFree(MemoryManager *m, void *p)
Definition memory.c:58
BROTLI_INTERNAL void BrotliInitMemoryManager(MemoryManager *m, brotli_alloc_func alloc_func, brotli_free_func free_func, void *opaque)
Definition memory.c:30
BROTLI_INTERNAL void BrotliBootstrapFree(void *address, MemoryManager *m)
Definition memory.c:180
BROTLI_INTERNAL void * BrotliBootstrapAlloc(size_t size, brotli_alloc_func alloc_func, brotli_free_func free_func, void *opaque)
Definition memory.c:170
void * opaque
Definition memory.h:29
brotli_free_func free_func
Definition memory.h:28
brotli_alloc_func alloc_func
Definition memory.h:27
void *(* brotli_alloc_func)(void *opaque, size_t size)
Definition types.h:71
void(* brotli_free_func)(void *opaque, void *address)
Definition types.h:81
#define BROTLI_BOOL
Definition types.h:49