This project implements a custom memory allocator using the Buddy Memory Allocation technique for the Operating Systems Course offered at ISI Kolkata. The allocator replaces system calls like malloc()
, calloc()
, realloc()
, and free()
, and provides functions for dynamic memory management using this custom technique.
Buddy memory allocation is a memory management technique that divides memory into partitions to try to satisfy a memory request as efficiently as possible. The memory is divided into blocks, and when a block is allocated, it may be split into two smaller "buddies." These buddies can later be merged back into a single block when they are both freed.
- balloc.c: Contains the implementation of the Buddy Memory Allocation system.
- balloc.h: Header file for
balloc.c
providing function declarations and necessary constants. - balloc-linked-list-traditional.c: A test file where a traditional linked list uses the custom buddy allocator for node management.
- linked-list-traditional-v2.c: A traditional linked list implementation using the default system allocator (for comparison with
balloc-linked-list-traditional.c
). - Testing.c: Contains matrix allocation and reallocation test cases, including two types of matrix allocations described in the OS End Sem paper.
- Mergefiles.c: Merges multiple files containing random integers into a single file using a buffer matrix allocated with the custom buddy memory allocator.
To compile the buddy memory allocator implementation (balloc.c
) into an object file:
gcc -g -Wall -c balloc.c
This generates balloc.o, the object file to be used for further testing.
This command compiles the traditional linked list implementation, where node allocation uses the custom buddy allocator:
gcc -g -Wall balloc.o balloc-linked-list-traditional.c
Run the program with:
./a.out 100
This will perform 100 insertions and deletions of nodes in the linked list using the buddy memory allocator.
To compare the performance with the default system allocator, compile and run the traditional linked list implementation (linked-list-traditional-v2.c):
gcc linked-list-traditional-v2.c
./a.out 100
This will perform 100 insertions and deletions of nodes using the default memory allocator.
To test matrix allocation and reallocation with the custom allocator:
gcc -g -Wall balloc.o Testing.c
./a.out
The matrix allocation test includes two types of matrix allocations:
Row-major order: In this method, rows of the matrix are stored contiguously in memory. Column-major order: In this method, columns of the matrix are stored contiguously in memory. This test will ensure that the buddy allocator can handle both type of dynamic memory allocation of arrays.
This program merges multiple text files containing random integers into a single file. It uses a buffer matrix allocated using the buddy allocator.
gcc -g -Wall balloc.o Mergefiles.c
./a.out
This creates 5 files with random integers, stores them into a buffer, and then merges them into a single output file merge.txt.
- https://www.isical.ac.in/~mandar/courses.html#os
- Data Structures and Algorithms by Alfred V. Aho
- https://people.kth.se/~johanmon/ose/assignments/buddy.pdf
- Dhruv (https://github.com/drmkn)
- Adrish (https://github.com/adrishpaik)
- Indrajit (https://github.com/Indrajit-hub)