2024-08-24 17:33:57 -04:00
|
|
|
#ifndef GC_ALLOC_H
|
|
|
|
#define GC_ALLOC_H
|
2024-08-22 21:38:25 -04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
// Metadata for allocated memory - Headers are stored in a linked list to keep
|
|
|
|
// track of alloc's and free's
|
|
|
|
struct gcHeader {
|
|
|
|
size_t size;
|
|
|
|
int free;
|
|
|
|
struct gcHeader *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Iterates over the galloc linked list attempting to find free space
|
|
|
|
struct gcHeader *findFree(struct gcHeader **prev, size_t size);
|
|
|
|
|
|
|
|
// Requests more memory from the kernel
|
|
|
|
struct gcHeader *requestMem(struct gcHeader *prev, size_t size);
|
|
|
|
|
|
|
|
// Performs allocations
|
|
|
|
void *galloc(size_t size);
|
|
|
|
|
|
|
|
// Frees memory allocated with galloc()
|
|
|
|
void gfree(void *ptr);
|
|
|
|
|
2024-08-24 17:33:57 -04:00
|
|
|
#endif /* GC_ALLOC_H */
|