blob: f613882fbec47649ea578bd86ea7859d3add0a46 (
plain) (
tree)
|
|
diheap
Drop In Heap
A simple thread-unsafe linked list heap without weird metadata between
allocations.
Licensed under MIT
Requirements:
stdint.h
uintmax_t, uintptr_t
stddef.h
NULL, size_t
string.h
memset
Example:
########################
#include "heap.h"
#define HEAP_SIZE 0x10000
struct heap stdlib_heap;
struct mutex stdlib_heap_mutex;
void*
malloc(size_t size)
{
void *r = 0;
mutex_lock(&stdlib_heap_mutex);
r = heap_alloc(&stdlib_heap, size);
mutex_unlock(&stdlib_heap_mutex);
return r;
}
void
free(void *ptr)
{
mutex_lock(&stdlib_heap_mutex);
heap_free(&stdlib_heap, size);
mutex_unlock(&stdlib_heap_mutex);
}
void
__stdlib_init(void)
{
heap_init(&stdlib_heap, (uintptr_t)sbrk(0), HEAP_SIZE);
//Heap is done baybee!
}
|