CustomHeapManager/include/CHM.h

42 lines
1.3 KiB
C

#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();