9#ifndef BROTLI_ENC_MEMORY_H_
10#define BROTLI_ENC_MEMORY_H_
15#include <brotli/types.h>
17#if defined(__cplusplus) || defined(c_plusplus)
21#if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \
22 !defined(BROTLI_ENCODER_EXIT_ON_OOM)
23#define BROTLI_ENCODER_EXIT_ON_OOM
30#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
32 size_t perm_allocated;
44#define BROTLI_ALLOC(M, T, N) \
45 ((N) > 0 ? ((T*)BrotliAllocate((M), (N) * sizeof(T))) : NULL)
48#define BROTLI_FREE(M, P) { \
49 BrotliFree((M), (P)); \
53#if defined(BROTLI_ENCODER_EXIT_ON_OOM)
54#define BROTLI_IS_OOM(M) (!!0)
56#define BROTLI_IS_OOM(M) (!!(M)->is_oom)
65#if defined(__clang_analyzer__) && !defined(BROTLI_ENCODER_EXIT_ON_OOM)
66#define BROTLI_IS_NULL(A) ((A) == nullptr)
68#define BROTLI_IS_NULL(A) (!!0)
81#define BROTLI_ENSURE_CAPACITY(M, T, A, C, R) { \
83 size_t _new_size = (C == 0) ? (R) : C; \
85 while (_new_size < (R)) _new_size *= 2; \
86 new_array = BROTLI_ALLOC((M), T, _new_size); \
87 if (!BROTLI_IS_OOM(M) && !BROTLI_IS_NULL(new_array) && C != 0) \
88 memcpy(new_array, A, C * sizeof(T)); \
89 BROTLI_FREE((M), A); \
104#define BROTLI_ENSURE_CAPACITY_APPEND(M, T, A, C, S, V) { \
106 BROTLI_ENSURE_CAPACITY(M, T, A, C, S); \
110#if defined(__cplusplus) || defined(c_plusplus)
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
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