]>
Commit | Line | Data |
---|---|---|
11b7501a SB |
1 | /* Copyright 2016 Google Inc. All Rights Reserved.\r |
2 | \r | |
3 | Distributed under MIT license.\r | |
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT\r | |
5 | */\r | |
6 | \r | |
7 | /* Macros for memory management. */\r | |
8 | \r | |
9 | #ifndef BROTLI_ENC_MEMORY_H_\r | |
10 | #define BROTLI_ENC_MEMORY_H_\r | |
11 | \r | |
12 | #include "../common/types.h"\r | |
13 | #include "./port.h"\r | |
14 | \r | |
15 | #if defined(__cplusplus) || defined(c_plusplus)\r | |
16 | extern "C" {\r | |
17 | #endif\r | |
18 | \r | |
19 | #if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \\r | |
20 | !defined(BROTLI_ENCODER_EXIT_ON_OOM)\r | |
21 | #define BROTLI_ENCODER_EXIT_ON_OOM\r | |
22 | #endif\r | |
23 | \r | |
24 | typedef struct MemoryManager {\r | |
25 | brotli_alloc_func alloc_func;\r | |
26 | brotli_free_func free_func;\r | |
27 | void* opaque;\r | |
28 | #if !defined(BROTLI_ENCODER_EXIT_ON_OOM)\r | |
29 | BROTLI_BOOL is_oom;\r | |
30 | size_t perm_allocated;\r | |
31 | size_t new_allocated;\r | |
32 | size_t new_freed;\r | |
33 | void* pointers[256];\r | |
34 | #endif /* BROTLI_ENCODER_EXIT_ON_OOM */\r | |
35 | } MemoryManager;\r | |
36 | \r | |
37 | BROTLI_INTERNAL void BrotliInitMemoryManager(\r | |
38 | MemoryManager* m, brotli_alloc_func alloc_func, brotli_free_func free_func,\r | |
39 | void* opaque);\r | |
40 | \r | |
41 | BROTLI_INTERNAL void* BrotliAllocate(MemoryManager* m, size_t n);\r | |
42 | #define BROTLI_ALLOC(M, T, N) ((T*)BrotliAllocate((M), (N) * sizeof(T)))\r | |
43 | \r | |
44 | BROTLI_INTERNAL void BrotliFree(MemoryManager* m, void* p);\r | |
45 | #define BROTLI_FREE(M, P) { \\r | |
46 | BrotliFree((M), (P)); \\r | |
47 | P = NULL; \\r | |
48 | }\r | |
49 | \r | |
50 | #if defined(BROTLI_ENCODER_EXIT_ON_OOM)\r | |
51 | #define BROTLI_IS_OOM(M) (!!0)\r | |
52 | #else /* BROTLI_ENCODER_EXIT_ON_OOM */\r | |
53 | #define BROTLI_IS_OOM(M) (!!(M)->is_oom)\r | |
54 | #endif /* BROTLI_ENCODER_EXIT_ON_OOM */\r | |
55 | \r | |
56 | BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager* m);\r | |
57 | \r | |
58 | #if defined(__cplusplus) || defined(c_plusplus)\r | |
59 | } /* extern "C" */\r | |
60 | #endif\r | |
61 | \r | |
62 | #endif /* BROTLI_ENC_MEMORY_H_ */\r |