Memalloc is a custom memory allocator implementation written in C. It provides efficient memory management functions similar to the standard malloc
, free
, and realloc
.
- Custom
malloc
implementation for dynamic memory allocation free
function to deallocate previously allocated memoryrealloc
function to resize or move allocated memory blocks- Efficient memory management using a free list approach
- Coalescing of adjacent free blocks to reduce fragmentation
- Splitting of large free blocks to minimize wasted space
To use the memalloc functions in your project:
-
Include the
memalloc.h
header file in your C source files: -
Use the following functions for memory management:
void *malloc(size_t size)
: Allocate memory of the specified sizevoid free(void *ptr)
: Deallocate previously allocated memoryvoid *realloc(void *ptr, size_t size)
: Resize or move an allocated memory block
The memory allocator uses a free list approach to manage memory blocks. It maintains a list of free memory blocks and performs the following optimizations:
- Coalescing: Merges adjacent free blocks to reduce fragmentation
- Splitting: Divides large free blocks to minimize wasted space
- First-fit allocation strategy: Finds the first suitable free block for allocation
For more details, refer to the comments in the memalloc.c
source file.
- This allocator is not thread-safe. Use appropriate synchronization mechanisms if used in a multi-threaded environment.
- The implementation assumes a contiguous memory model and may not be suitable for all systems or use cases.
Contributions to improve the memory allocator are welcome. Please submit pull requests or open issues to discuss potential enhancements.
This project is open-source and available under the MIT License.