Fixed a lot of errors and expanded functionality.

This commit is contained in:
2024-03-02 06:42:02 -08:00
parent f341253aa8
commit 7464c85692
5 changed files with 455 additions and 285 deletions

42
include/CHM.h Normal file
View File

@@ -0,0 +1,42 @@
#pragma once
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/syscall.h>
#define ALIGN4(s) (((((s)-1)>>2)<<2)+4)
#define ALIGN16(s) (((s) + 15) & ~0x0F)
#define ALIGNMENT 4
#define BLOCK_SIZE sizeof(struct Block)
#define MINIMUM_BLOCK_SIZE (sizeof(struct Block) + 16)
enum MemMode : unsigned char
{
MEM_MODE_SPEED, // Memory will be allocated more quickly but loses memory efficiency.
MEM_MODE_EFFICIENCY, // Memory will be allocated more slowly but gains memory efficiency.
MEM_MODE_BALANCED // Memory will be allocated as quickly as possible but also for the sake of memory efficiency.
};
void set_memory_mode(enum MemMode new_mode);
enum MemMode get_memory_mode();
/// Will find or allocate a memory block appropriately.
/// @param [in] size The size of the memory block to request.
/// @returns The allocated memory address on the heap.
void *malloc(size_t size);
void *realloc(void *ptr, size_t newSize);
/// Will flag the provided memory as free and will defragment other blocks adjacent to it.
/// @param [in] ptr The memory to flag as free.
void free(void *ptr);
/// Will retrieve the current real byte size of the heap.
/// @returns The size in bytes.
size_t get_heap_size();
/// Will check memory blocks on program exit if there's dangling memory.
void check_memory();