16#ifndef MRBC_SRC_ALLOC_H_
17#define MRBC_SRC_ALLOC_H_
22#if defined(MRBC_ALLOC_LIBC)
61#if !defined(MRBC_ALLOC_LIBC)
72#define mrbc_free(vm,ptr) mrbc_raw_free(ptr)
73#define mrbc_realloc(vm,ptr,size) mrbc_raw_realloc(ptr, size)
76#if defined(MRBC_ALLOC_VMID)
78void *mrbc_alloc(
const struct VM *vm,
unsigned int size);
79void *mrbc_calloc(
const struct VM *vm,
unsigned int nmemb,
unsigned int size);
80void mrbc_free_all(
const struct VM *vm);
81void mrbc_set_vm_id(
void *ptr,
int vm_id);
82int mrbc_get_vm_id(
void *ptr);
85#define mrbc_alloc(vm,size) mrbc_raw_alloc(size)
86#define mrbc_free_all(vm) ((void)0)
87#define mrbc_set_vm_id(ptr,id) ((void)0)
88#define mrbc_get_vm_id(ptr) 0
92void mrbc_alloc_start_profiling(
void);
93void mrbc_alloc_stop_profiling(
void);
95void mrbc_alloc_print_statistics(
void);
96void mrbc_alloc_print_pool_header(
void *pool_header);
97void mrbc_alloc_print_memory_block(
void *pool_header);
98void mrbc_alloc_print_memory_pool(
void);
102#elif defined(MRBC_ALLOC_LIBC)
106#if defined(MRBC_ALLOC_VMID)
107#error "Can't use MRBC_ALLOC_LIBC with MRBC_ALLOC_VMID"
118static inline void *
mrbc_raw_calloc(
unsigned int nmemb,
unsigned int size) {
119 return calloc(nmemb, size);
125 return realloc(ptr, size);
136static inline void mrbc_free(
const struct VM *vm,
void *ptr) {
139static inline void * mrbc_realloc(
const struct VM *vm,
void *ptr,
unsigned int size) {
140 return realloc(ptr, size);
142static inline void *mrbc_alloc(
const struct VM *vm,
unsigned int size) {
145static inline void mrbc_free_all(
const struct VM *vm) {
147static inline void mrbc_set_vm_id(
void *ptr,
int vm_id) {
149static inline int mrbc_get_vm_id(
void *ptr) {
void * mrbc_raw_alloc(unsigned int size)
void mrbc_alloc_statistics(struct MRBC_ALLOC_STATISTICS *ret)
void * mrbc_raw_alloc_no_free(unsigned int size)
void * mrbc_raw_realloc(void *ptr, unsigned int size)
void mrbc_init_alloc(void *ptr, unsigned int size)
unsigned int mrbc_alloc_usable_size(void *ptr)
void * mrbc_raw_calloc(unsigned int nmemb, unsigned int size)
void mrbc_raw_free(void *ptr)
void mrbc_cleanup_alloc(void)
for memory allocation profiling functions. if you use this, define MRBC_USE_ALLOC_PROF pre-processor ...
Return value structure for mrbc_alloc_statistics function.
unsigned int total
returns total memory.
unsigned int used
returns used memory.
unsigned int fragmentation
returns memory fragmentation count.
unsigned int free
returns free memory.
uint8_t vm_id
vm_id : 1..MAX_VM_COUNT