Professional Documents
Culture Documents
B.YASWANTH (RA211030010262) : Department of Networking and Communications
B.YASWANTH (RA211030010262) : Department of Networking and Communications
B.YASWANTH (RA211030010262) : Department of Networking and Communications
P.LAXMI Narayana[RA211030010258)
A.HARSHA[RA211030010249]
degree of
M.TECH INTEGRATED
COMPUTER SCIENCE
ENGINEERING
with specialization
in CYBER
SECURITY
Certified that this project report titled “MEMORY ALLOCATION” is the Bonafide work of
“B.YASWANTH [RegNo:RA2211030010262],P . L A X M I N A R A Y A N A [Reg No:RA2211030010258]
A.HARSHA[Reg No:RA2211030010146]” who carried out the project work under my supervision.
Certified further, that to the best of my knowledge, the work reported herein does not form part of
anyother thesis or dissertation based on which a degree or award was conferred on an earlier occasion
for this or any other candidate.
2
TABLE OF CONTENTS
S.NO CONTENTS PAGE NO
1. OBJECTIVE 4
2. ABSTRACT 5
3. INTRODUCTION 6
4. PROBLEM STATEMENT 7
5. LIMITATIONS 8
6. BLOCK DIAGRAM 9
7. PROGRAM 10-11
8. OUTPUT 12
9. CONCLUSION 13
10. REFERENCES 14
3
OBJECTIVE
4
ABSTRACT
5
INTRODUCTION:
1. Block Structure:
- Block is a custom structure used to keep track of allocated
memory blocks.
- It contains two members: size to store the size of the allocated
memory block and next to maintain a linked list of allocated blocks.
3. my_malloc Function:
- Custom memory allocation function that mimics the behavior of
the standard malloc function.
- It allocates a block of memory using malloc, creates a
corresponding Block structure to track it, and adds the structure to
the linked list.
4. my_realloc Function:
- Custom memory reallocation function that mimics the behavior
of the standard realloc function.
- It reallocates memory using realloc, updates the size in the
corresponding Block structure, and maintains the linked list.
6
PROBLEM STATEMENT:
7
LIMITATIONS:
8
BLOCK DIAGRAM:
+----------------------------------+
| Main Program (main function) |
+----------------------------------+
|
v
+----------------------------------+
| Custom Memory Allocation Functions |
+----------------------------------+
|
v
+----------------------------------+
| Data Structures |
| - Block structure |
| - allocated_blocks (linked list)|
+----------------------------------+
|
v
+----------------------------------+
| Standard Library Memory Functions|
| - malloc, realloc, free |
+----------------------------------+
|
v
+----------------------------------+
| Error Handling |
| - Allocation and reallocation |
+----------------------------------+
|
v
+----------------------------------+
| Print Statements |
+----------------------------------+
9
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
if (ptr == NULL) {
// Handle allocation failure
fprintf(stderr, "Memory allocation failed\n");
return NULL;
}
block->size = size;
block->next = allocated_blocks;
allocated_blocks = block;
return ptr;
}
if (new_ptr == NULL) {
// Handle reallocation failure
fprintf(stderr, "Memory reallocation failed\n");
return NULL;
}
return new_ptr;
}
// Find and remove the corresponding Block structure from the list
Block* current = allocated_blocks;
Block* previous = NULL;
11
} else {
allocated_blocks = current->next;
}
free(current);
break;
}
previous = current;
current = current->next;
}
}
int main() {
int* int_ptr = (int*)my_malloc(sizeof(int));
*int_ptr = 42;
printf("Value: %d\n", *int_ptr);
my_free(int_ptr);
my_free_all(); // Release all allocated memory
return 0;
}
12
OUTPUT:
13
CONCLUSION:
a custom memory management system implemented in C. It
allows you to allocate, reallocate, and free memory using
custom functions (my_malloc, my_realloc, my_free) while
also keeping track of the allocated memory blocks. Here's a
summary of the code:
14
REFERENCES:
Here are some references that you can look up for more information
on memory allocation:
Wikipedia:
https://en.m.wikipedia.org/wiki/C_dynamic_memory_allocation
Greeks for greeks:
https://www.geeksforgeeks.org/dynamic-memory-allocation-in-c-using-
malloc-calloc-free-and-realloc/
15