This project implements a memory allocation system in C, that i made as part of my Operating systems 2 course.
The project consists of two files:
heap.h
: Header file containing function prototypes and struct definitions.heap.c
: Source file containing the implementation of memory allocation functions.
Initializes the memory manager.
Frees all allocated memory and resets the memory manager.
Allocates a block of memory of the given size.
Allocates memory for an array of elements, initialized to zero.
Changes the size of the memory block pointed to by memblock
.
Frees the memory block pointed to by memblock
.
Validates the integrity of the heap.
Determines the type of the pointer.
Returns the size of the largest used memory block.
To use the memory allocation functions, include heap.h
in your source files and link with heap.c
.
#include "heap.h"
#include <stdio.h>
int main() {
heap_setup();
// Example usage
void *ptr = heap_malloc(10);
heap_free(ptr);
heap_clean();
return 0;
}