Browse Source

Added some debug stuff

tree_alloc
Thomas Johnson 1 year ago
parent
commit
26580c0355
  1. 37
      main.c

37
main.c

@ -1,3 +1,4 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
@ -18,6 +19,42 @@ void error(char *msg) {
printf("=== ALLOCATOR ERROR ===\n%s\n====== END ERROR ======\n", msg);
}
struct AllocationRecord {
uintptr_t size;
void *allocation;
void *reference;
struct AllocationRecord *next;
struct AllocationRecord *prev;
}
void insert_record(struct AllocationRecord *dummy, void *allocation, uintptr_t size) {
struct AllocationRecord *record = malloc(sizeof(struct AllocationRecord));
record->size = size;
record->allocation = allocation;
record->reference = malloc(size);
record->next = dummy;
record->prev = dummy->prev;
dummy->prev->next = record;
dummy->prev = record;
dummy->size += 1;
memcpy(record->reference, allocation, size);
}
void delete_record(struct AllocationRecord *dummy, struct AllocationRecord *delete) {
free(delete->reference);
delete->prev->next = delete->next;
delete->next->prev = delete->prev;
free(delete);
dummy->size -= 1;
}
int validate_record(struct AllocationRecord *record) {
if (memcmp(record->allocation, record->reference, record->size) != 0) {
return 0;
}
return 1;
}
int main() {
printf("Hello, World!\n");
struct Arena arena = {

Loading…
Cancel
Save