Buddy-system memory allocator.
#include <stdint.h>
#include <sys/queue.h>
Go to the source code of this file.
◆ BUDDY_ALIGN_PREF
#define BUDDY_ALIGN_PREF (32 - 2 * sizeof(void*) - sizeof(uint32_t) - sizeof(purpose_t)) |
◆ buddy_list_bucket_t
Bucket of 2^order sized free memory blocks.
◆ buddy_list_t
Metadata about this particular block (and stored at the beginning of this block). One per allocated block of memory. Should be 32 bytes to not screw up alignment.
◆ purpose_t
◆ valid_t
◆ purpose
◆ valid
◆ buddy_alloc()
void * buddy_alloc |
( |
unsigned | size | ) |
|
Find the smallest block that will contain size and return it. Note this returns the memory allocated and usable, not the entire buffer. This may involve breaking up larger blocks.
- Parameters
-
size | The size of the data this allocation must be able to hold. |
Definition at line 234 of file buddy.c.
◆ buddy_free()
void buddy_free |
( |
void * | ptr | ) |
|
Free the given pointer (and coalesce it with its buddy if possible).
- Parameters
-
Definition at line 137 of file buddy.c.
◆ create_buddy_table()
Pass in the power of two e.g., passing 5 will yield 2^5 = 32.
- Parameters
-
power_of_two | The largest "order" this table will support. |
<Minimum block order
<Minimum block order
<Minimum block order
<Minimum block order
Definition at line 288 of file buddy.c.