-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_pool.h
More file actions
executable file
·68 lines (50 loc) · 2.31 KB
/
memory_pool.h
File metadata and controls
executable file
·68 lines (50 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef MEMORY_POOL_H
#define MEMORY_POOL_H
#include <stddef.h>
#include <stdio.h>
#ifndef MEMORY_POOL_EXPORT
#define MEMORY_POOL_EXPORT
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*pool_exception_handler_s)(const char *name, const void *starting_addr, const void *last_addr, const void *error_location);
typedef pool_exception_handler_s pool_exception_handler_type;
typedef struct pool_allocator_type {
void *(*alloc)(size_t number_of_bytes);
void (*dealloc)(void *memory);
} pool_allocator_type;
typedef struct pool_mutex_type {
void *mutex;
void (*mutex_lock)(void *mutex);
void (*mutex_unlock)(void *mutex);
} pool_mutex_type;
typedef struct pool_result_type {
void *pool;
size_t actual_size; /* actual size including overhead in bytes */
} pool_result_type;
MEMORY_POOL_EXPORT size_t pool_minimum_overhead_size(void);
MEMORY_POOL_EXPORT void *pool_create(size_t size); /* uses OS heap and uses no mutex */
MEMORY_POOL_EXPORT
pool_result_type pool_create_with_allocator_or_mutex_support(
size_t size, /* minimum number of bytes */
pool_allocator_type *allocator, /* allocator: optional, can be NULL (uses OS heap) */
pool_mutex_type *pool_mutex /* mutex: optional, can be NULL (no thread safety) */
);
MEMORY_POOL_EXPORT void pool_destroy(void *pool);
MEMORY_POOL_EXPORT pool_exception_handler_type pool_set_heap_corruption_handler(void *pool, pool_exception_handler_type handler);
MEMORY_POOL_EXPORT pool_exception_handler_type pool_set_memory_leak_handler(void *pool, pool_exception_handler_type handler);
MEMORY_POOL_EXPORT pool_exception_handler_type pool_set_dangling_pointer_handler(void *pool, pool_exception_handler_type handler);
MEMORY_POOL_EXPORT void pool_set_name(void *pool, const char *name);
MEMORY_POOL_EXPORT const char *pool_get_name(void *pool);
MEMORY_POOL_EXPORT FILE *pool_set_log_file(void *pool, FILE *log_file); /* returns the previous FILE pointer */
MEMORY_POOL_EXPORT FILE *pool_get_log_file(void *pool);
MEMORY_POOL_EXPORT void *pool_malloc(void *pool, size_t size);
MEMORY_POOL_EXPORT void *pool_calloc(void *pool, size_t count, size_t element_size);
MEMORY_POOL_EXPORT void *pool_realloc(void *pool, void *memory, size_t new_size);
MEMORY_POOL_EXPORT void pool_free(void *pool, void *memory);
MEMORY_POOL_EXPORT void pool_defragment(void *pool);
#ifdef __cplusplus
}
#endif
#endif