mirror of
https://github.com/google/brotli.git
synced 2024-11-29 06:31:06 +00:00
801f5f37ee
* add Brotli*TakeOutput methods * * flushing now doesn't require additional call * add Brotli*Version methods * moved public headers to 'public' directory * removed C++ API * do not assume STDC_VERSION is defined
63 lines
1.6 KiB
C
63 lines
1.6 KiB
C
/* Copyright 2016 Google Inc. All Rights Reserved.
|
|
|
|
Distributed under MIT license.
|
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
/* Macros for memory management. */
|
|
|
|
#ifndef BROTLI_ENC_MEMORY_H_
|
|
#define BROTLI_ENC_MEMORY_H_
|
|
|
|
#include "../public/types.h"
|
|
#include "./port.h"
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
extern "C" {
|
|
#endif
|
|
|
|
#if !defined(BROTLI_ENCODER_CLEANUP_ON_OOM) && \
|
|
!defined(BROTLI_ENCODER_EXIT_ON_OOM)
|
|
#define BROTLI_ENCODER_EXIT_ON_OOM
|
|
#endif
|
|
|
|
typedef struct MemoryManager {
|
|
brotli_alloc_func alloc_func;
|
|
brotli_free_func free_func;
|
|
void* opaque;
|
|
#if !defined(BROTLI_ENCODER_EXIT_ON_OOM)
|
|
BROTLI_BOOL is_oom;
|
|
size_t perm_allocated;
|
|
size_t new_allocated;
|
|
size_t new_freed;
|
|
void* pointers[256];
|
|
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
|
|
} MemoryManager;
|
|
|
|
BROTLI_INTERNAL void BrotliInitMemoryManager(
|
|
MemoryManager* m, brotli_alloc_func alloc_func, brotli_free_func free_func,
|
|
void* opaque);
|
|
|
|
BROTLI_INTERNAL void* BrotliAllocate(MemoryManager* m, size_t n);
|
|
#define BROTLI_ALLOC(M, T, N) ((T*)BrotliAllocate((M), (N) * sizeof(T)))
|
|
|
|
BROTLI_INTERNAL void BrotliFree(MemoryManager* m, void* p);
|
|
#define BROTLI_FREE(M, P) { \
|
|
BrotliFree((M), (P)); \
|
|
P = NULL; \
|
|
}
|
|
|
|
#if defined(BROTLI_ENCODER_EXIT_ON_OOM)
|
|
#define BROTLI_IS_OOM(M) (!!0)
|
|
#else /* BROTLI_ENCODER_EXIT_ON_OOM */
|
|
#define BROTLI_IS_OOM(M) (!!(M)->is_oom)
|
|
#endif /* BROTLI_ENCODER_EXIT_ON_OOM */
|
|
|
|
BROTLI_INTERNAL void BrotliWipeOutMemoryManager(MemoryManager* m);
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
} /* extern "C" */
|
|
#endif
|
|
|
|
#endif /* BROTLI_ENC_MEMORY_H_ */
|