summaryrefslogtreecommitdiffstats
path: root/README.txt
blob: f613882fbec47649ea578bd86ea7859d3add0a46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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!
}