1 /* Copyright 2016 Google Inc. All Rights Reserved.
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
7 /* Macros for memory management. */
9 #ifndef BROTLI_ENC_MEMORY_H_
10 #define BROTLI_ENC_MEMORY_H_
12 #include "../common/types.h"
15 #if defined(__cplusplus) || defined(c_plusplus)
19 #if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \
20 !defined(BROTLI_ENCODER_EXIT_ON_OOM)
21 #define BROTLI_ENCODER_EXIT_ON_OOM
24 typedef struct MemoryManager
{
25 brotli_alloc_func alloc_func
;
26 brotli_free_func free_func
;
28 #if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
30 size_t perm_allocated
;
34 #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
37 BROTLI_INTERNAL
void BrotliInitMemoryManager(
38 MemoryManager
* m
, brotli_alloc_func alloc_func
, brotli_free_func free_func
,
41 BROTLI_INTERNAL
void* BrotliAllocate(MemoryManager
* m
, size_t n
);
42 #define BROTLI_ALLOC(M, T, N) ((T*)BrotliAllocate((M), (N) * sizeof(T)))
44 BROTLI_INTERNAL
void BrotliFree(MemoryManager
* m
, void* p
);
45 #define BROTLI_FREE(M, P) { \
46 BrotliFree((M), (P)); \
50 #if defined(BROTLI_ENCODER_EXIT_ON_OOM)
51 #define BROTLI_IS_OOM(M) (!!0)
52 #else /* BROTLI_ENCODER_EXIT_ON_OOM */
53 #define BROTLI_IS_OOM(M) (!!(M)->is_oom)
54 #endif /* BROTLI_ENCODER_EXIT_ON_OOM */
56 BROTLI_INTERNAL
void BrotliWipeOutMemoryManager(MemoryManager
* m
);
58 #if defined(__cplusplus) || defined(c_plusplus)
62 #endif /* BROTLI_ENC_MEMORY_H_ */