import
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#ifndef INCLUDED_BUDDY_H
|
||||
#define INCLUDED_BUDDY_H
|
||||
|
||||
#ifndef INCLUDED_OS_TYPES_H
|
||||
#include <os_types.h>
|
||||
#endif /*INCLUDED_OS_TYPES_H*/
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* https://www.gingerbill.org/article/2021/12/02/memory-allocation-strategies-006/ */
|
||||
|
||||
typedef struct buddy_block_t{
|
||||
os_size_t size;
|
||||
os_bool_t is_free;
|
||||
}buddy_block_t;
|
||||
|
||||
typedef struct buddy_t{
|
||||
buddy_block_t* head;
|
||||
buddy_block_t* tail;
|
||||
int alignment;
|
||||
}buddy_t;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
void buddy_init(buddy_t* self, void* buf, os_size_t buf_size /*POWER_OF_2*/, os_size_t alignment /*POWER_OF_2*/);
|
||||
|
||||
void buddy_destroy(buddy_t* self);
|
||||
|
||||
void* buddy_alloc(buddy_t* self, os_size_t size);
|
||||
|
||||
void* buddy_calloc(buddy_t* b, os_size_t count, os_size_t size);
|
||||
|
||||
void* buddy_realloc(buddy_t* self, void* ptr, os_size_t size);
|
||||
|
||||
void buddy_free(buddy_t* self, void* ptr);
|
||||
|
||||
#endif /*INCLUDED_BUDDY_H*/
|
||||
Reference in New Issue
Block a user