CMagic  0.5.0
Portable C library of utilities and data structures
memory.h
Go to the documentation of this file.
1 
8 #ifndef CMAGIC_MEMORY_H
9 #define CMAGIC_MEMORY_H
10 
11 #include <stdbool.h>
12 #include <stddef.h>
13 #include <stdlib.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
29 void
30 cmagic_memory_init(void *static_memory_pool, size_t static_memory_pool_size);
31 
55 void *
56 cmagic_memory_malloc(size_t size);
57 
75 void *
76 cmagic_memory_realloc(void *ptr, size_t size);
77 
85 
88 
91 
94 
98 
101 
102 };
103 
111 cmagic_memory_free_ext(void *ptr);
112 
128 void
129 cmagic_memory_free(void *ptr);
130 
138 bool
139 cmagic_memory_is_allocated(void *ptr);
140 
144 size_t
146 
153 size_t
155 
165 size_t
167 
171 typedef void* (*cmagic_memory_malloc_fptr_t)(size_t size);
172 
176 typedef void* (*cmagic_memory_realloc_fptr_t)(void* ptr, size_t size);
177 
181 typedef void (*cmagic_memory_free_fptr_t)(void *ptr);
182 
187 typedef struct {
188  cmagic_memory_malloc_fptr_t malloc_function;
189  cmagic_memory_realloc_fptr_t realloc_function;
190  cmagic_memory_free_fptr_t free_function;
192 
197  malloc, realloc, free
198 };
199 
205 };
206 
207 #ifdef __cplusplus
208 } // extern "C"
209 #endif
210 
211 #endif /* CMAGIC_MEMORY_H */
size_t cmagic_memory_get_free_bytes(void)
Returns number of free bytes in the memory pool.
void cmagic_memory_init(void *static_memory_pool, size_t static_memory_pool_size)
Sets a memory range where all dynamic allocated objects will reside.
void(* cmagic_memory_free_fptr_t)(void *ptr)
A pointer to free like function.
Definition: memory.h:181
Set of allocation functions. Used in some CMagic structures to specify a desired memory pool...
Definition: memory.h:187
bool cmagic_memory_is_allocated(void *ptr)
Checks if the memory block was allocated before with cmagic_memory_malloc or cmagic_memory_realloc an...
cmagic_memory_free_result
Type of result returned from cmagic_memory_free_ext.
Definition: memory.h:84
void *(* cmagic_memory_malloc_fptr_t)(size_t size)
A pointer to malloc like function.
Definition: memory.h:171
enum cmagic_memory_free_result cmagic_memory_free_ext(void *ptr)
Extended version of cmagic_memory_free.
void * cmagic_memory_realloc(void *ptr, size_t size)
Reallocates memory block changing its original size.
size_t cmagic_memory_get_allocated_bytes(void)
Returns the sum of currently allocated bytes.
void *(* cmagic_memory_realloc_fptr_t)(void *ptr, size_t size)
A pointer to realloc like function.
Definition: memory.h:176
void cmagic_memory_free(void *ptr)
Deallocates a block of memory previously allocated by a call to cmagic_memory_malloc or cmagic_memory...
Definition: memory.h:87
static const cmagic_memory_alloc_packet_t CMAGIC_MEMORY_ALLOC_PACKET_STD
Allocation from the standard library.
Definition: memory.h:196
static const cmagic_memory_alloc_packet_t CMAGIC_MEMORY_ALLOC_PACKET_CUSTOM_CMAGIC
Custom allocation from the CMagic library.
Definition: memory.h:203
void * cmagic_memory_malloc(size_t size)
Dynamically allocates a block of memory of requested size, returning a pointer to the beginning of th...
size_t cmagic_memory_get_allocations(void)
Returns number of allocations made by cmagic_memory_malloc.