This project implements a heap management system in C, providing functionalities for dynamic memory allocation, deallocation, and memory usage inspection.
The heap management system consists of a header file (cHEAP.h
) and an implementation file (cHEAP.c
). It includes functionalities to allocate, deallocate, and inspect memory blocks within a fixed-size memory pool.
-
Header File (
cHEAP.h
):- Defines constants, data types, and function prototypes.
- Contains macros for error handling.
-
Implementation File (
cHEAP.c
):- Implements memory management functions.
- Defines a fixed-size memory pool and free list for managing memory blocks.
_initializer_()
: Initializes the heap.cHEAP_AllocateNew()
: Allocates memory blocks.cHEAP_Release()
: Deallocates memory blocks.cHEAP_InspectFreeSpace()
: Prints information about free memory blocks.cHEAP_Length()
: Gets the size of an allocated memory block.cHEAP_IfAllocatable()
: Checks if memory of a given size can be allocated.cHEAP_Nullify()
: Nullifies memory contents.cHEAP_GetTotalFreeSpace()
: Gets total free space in the heap.cHEAP_GetTotalAllocatedSpace()
: Gets total allocated space in the heap.cHEAP_DeallocateAll()
: Deallocates all memory blocks in the heap.
The system includes error handling mechanisms using errno
and custom error messages for scenarios like segmentation faults, non-accessible memory, attempted deallocation of already freed memory, and illegal memory access.
To use the heap management system, include the cHEAP.h
header file in your project and link it with the cHEAP.c
implementation file. Then, you can call the provided memory management functions as needed.