os project 2
os project 2
BACHELOR OF TECHNOLOGY
IN
INFORMATION TECHNOLOGY
SUBMITTED
2024-2025
JOGINPALLY B.R ENGINEERING COLLEGE
(UGC Autonomous)
Accredited by NAAC with A+ Grade, Recognized under Sec. 2(f) of UGC Act. 1956
Approved by AICTE and Affiliated to Jawaharlal Nehru Technological University,
Hyderabad
Bhaskar Nagar, Yenkapally, Moinabad,
RangaReddy, Hyderabad, Telangana- 500075.
CERTIFICATE
This is to certify that the Lab Project entitled “DYNAMIC MEMORY ALLOCATOR” is the
bonafide work carried out by Padala Jaya Prakash (23J21A1237),Ch Mani Deekshith
(23J21A1211), J Ananth Kumar (23J21A1216) of II B.Tech IT, under our guidance and
supervision. The Lab Project Report is submitted to Joginpally BR Engineering College
(UGC Autonomous) Hyderabad in partial fulfilment of requirements of the award of the
degree of Bachelor of Technology in Information Technology during the academic year
2024-2025.
JOGINPALLY B.R. ENGINEERING COLLEGE
ACKNOWLEDGEMENT
We express our hearted thank you to our principal Dr. B Venkata Ramana Reddy for giving
us spontaneous encourage for completing the Lab project.
We are really thank you to our HOD Dr. T. Sheshagiri for his time to time, much needed
valuable guidance throughout our Lab project.
We would like to express our sincere gratitude to our LAB PROJECT INTERNAL GUIDE
Dr.shaik Aleem Basha who has guided and supported us through every stage in the Lab
Project.
DECLARATION
We hereby declare that our Lab Project entitled “DYNAMIC MEMORY ALLOCATOR” is the
work done during the academic year 2024-2025, II year - I-Sem and our Lab Project is submitted
in partial fulfilment of the requirements for the award of B.Tech degree in Information Technology
from JOGINPALLY B.R. ENGINEERING COLLEGE (UGC Autonomous), Hyderabad.
ABSTRACT
CONTENTS
1. COVER PAGE
ABSTRACT
2. INTRODUCTION
2.1.1 FRAGMENTATION
6 TEST CASE
7 EXPERIMENTAL RESULTS
8 CONCLUSION
9 REFERENCE
INTRODUCTION
Memory manager performs memory allocation process. It is reported that dynamic memory
management consumes 23%-38% of the time in six allocation-intensive C programs running
on 17-SPECmarks SPARC architecture with 80 MB of memory [1]. Object-oriented programs
have a very high object creation rate and, therefore, the speed of memory allocation is crucial
for improving the system performanc
Received Date : 10.12.2004 Accepted Date: 27.03.2005 Until now, improved software
techniques by using various data structures are separated into three different categories:
Bitmap, Linked List techniques, Buddy Systems.
Bitmap implementation use a bitmap, where each bit represents some portions of memory and
indicates whether it is free or occupied.
The most popular method in dynamic memory allocation techniques is Linked Lists. First Fit,
Best Fit, Worst Fit and Next Fit Linked List techniques are well known and frequently used.
Although Memory usage of these algorithms is good, list structure leads to decrease running
speed of these algorithms. Each memory request (malloc function in C programming language)
causes to search all list sequentially. The memory manager scans among the list until it finds
blocks that are big enough. The hole is then broken into two pieces; one for the process and
one for the unused memory.
The most popular method in dynamic memory allocation techniques is Linked Lists. First Fit,
Best Fit, Worst Fit and Next Fit Linked List techniques are well known and frequently used.
Although Memory usage of these algorithms is good, list structure leads to decrease running
speed of these algorithms. Each memory request (malloc function in C programming language)
causes to search all list sequentially. The memory manager scans among the list until it finds
blocks that are big enough. The hole is then broken into two pieces; one for the process and
one for the unused memory.
Background
1. Efficient Memory Use: Dynamic memory allocation enables programs to allocate memory
only when needed, reducing memory waste and improving overall system efficiency.
2.1. FRAGMENTATION
Fragmentation is one of the most important problem that an allocator encounters. The
fragmentation problem prevents memory to be used effectively. Fragmentation is classified as
external or internal [6].
• Bitmap
• Linked List techniques: First Fit, Best Fit, Next Fit, Worst Fit
• Buddy Systems: Binary, Fibonacci,
Weighted
In spite of simplicity, the main problem is that when it has been decided to bring a k unit process
into memory, the memory manager must search the bit map to find k consecutive 0 bits in the
bit map. Searching a bit map for a request is a slow operation, so in practice, bit maps are not
often used.
Figure 1: (a) A part of memory with five processes and 3 holes. The tick marks show the
memory allocation units. The shaded regions (0 in the bit map) are free. (b) The corresponding
bit map
It is expected from this strategy that unused holes are decreased. But, this is not performed and
first fit algorithm may be more successful from this point of view. Because, after allocation are
performed, the remainder may be quite small and perhaps unusable for next larger request. A
little time later, memory has a lot of small blocks and total unused area is too much than that
of first fit.
Although Buddy system is faster, it has a very important disadvantage. Buddy systems are
inefficient in memory usage. Though the linked list techniques have only external
fragmentation, buddy systems have both internal and external fragmentation. Basis reason of
this problem is that allocated blocks are power of two (for Binary buddy system). Therefore,
first request size round up to smallest number that is power of two (for binary buddy) then
allocation process is performed.
3.3.1. Binary Buddy System Working mechanism of Binary buddy system is as follows: We
start with the entire block of size 2U. When a request of size S is made: If 2U-1 < S<= 2U then
allocate the entire block of size 2U. Else, split this block into two buddies, each of size 2U-1.
If U-2< S<= 2U-1 then allocate one of the two buddies. Otherwise one of the two buddies is
split in half again. This process is repeated until the smallest block greater or equal to S is
generated [7].
Figure 3 shows the settlement of binary buddy system at binary tree. Striped circle, white circle
and gray circle represent respectively split blocks for allocation, leave nodes that show free
blocks, nodes that shows used memory chunks.
System
According to this definition, the elements of Fibonacci series: 0, 1, 2, 3, 5, 8, 13, 21, 34, 55,
89, 144, 233, 377, 610, 987...
3.3.3. Weighted Buddy System At the Weighted Buddy system, block sizes are as 2k or 3* 2k.
When blocks are split, applied rules are showed in figure 5 and 6.
As showed in figure 5a, If split block size is 2k+2, this block are split to 3*2k+2 and 2k block
size. If block size is 3*2k+2(Figure 6b), it separated into 2k+1 and 2k block sizes [3*2k -> (2k+1,
2k)].
4. SIMULATION AND
PERFORMANCE ANALYSIS
Some of the examined software techniques are simulated for performance analysis by using
C++ programming language. For this purpose, First Fit, Best fit, Worst Fit, Bit map, Binar y
Buddy and Weighted Buddy software techniques are simulated. Simulation results are obtained
for selected performance criteria that are fragmentation, allocation and deallocation duration in
respect of memory size and maximum allocatable object size. (Figure 8-10) In practice, nodes
which have a few fields for holding allocation information are defined using “struct NODE”
structure. This structure consist of field which hold father, left child, right child in tree structure
and next address in list. Another field indicates status of blocks. If the value is ‘1’, blocks are
allocated, otherwise they are free. Allocation and deallocation processes are executed by using
tree or list which is formed based on this defined structure. Defined specially by Mymalloc and
Myfree functions at the program are called randomly with 66%- 33% probabilities respectively.
Generated and allocated values are saved in an array. When Myfree function is called, a value
is selected randomly and then these blocks are deallocated. This array hold allocated address
values. The aim of using this array is that it is not possible to deallocate the address which has
not been allocated.
Allocation processes are performed by using generated random numbers in program. Internal
and external fragmentation is calculated after each allocation process. In this practice, total
fragmentation is calculated by using average internal and external values for 100 steps.
Buddy systems suffer from both internal and external fragmentation. The others have only
external fragmentation. Internal and external fragmentation values of binary and weighted
buddy systems are showed graphically in figure 7.
As shown in figure, it can be observed that Weighted buddy system suffers from internal
fragmentation less than Binary buddy. In contrast, in respect of external fragmentation binary
buddy is more successful. Another result obtained from this figure is that maximum allocatable
block number is directly proportional to external fragmentation.
In this study, although results of all techniques are obtained in respect of performance criteria,
Graphics are drawn only for the best method in each category. In this way, the performance of
categorically classified methods is evaluated.
Buddy Systems
Figure 9 shows that, according to allocation process, the best performance technique is binary
buddy, the worst is bitmap. Search process in tree structure can be done in shorter time than in
list structure. So, Buddy systems have the best performance in respect of allocation process
duration. In contrast, in bit map techniques, allocation is faster at small memory sizes due to
searching at bits and not splitting. The bigger memory size, the slower allocation time in the
bit map.
In figure 10, in respect of deallocation duration performance criteria, the most successful
technique is observed as bit map. As coalescing process is used in bitmap technique,
deallocation process is performed in short time by updating the
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
1024- 1024- 1024- 512- 512-64512-32256-64256-32256-16
256 128 64 128
4.5
4
3.5
3
2.5
2
1.5
1
0.5
0
1024- 1024- 1024- 512- 512-64512-32256-64256-32256-16
256 128 64 128
(micro second)
3.5
2.5
CODE
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int process_id;
int arrival_time;
int burst_time;
int completion_time;
int turn_around_time;
int waiting_time;
} Process;
// Calculate completion time, turn around time, and waiting time for each process
processes[0].completion_time = processes[0].arrival_time + processes[0].burst_time;
processes[0].turn_around_time = processes[0].completion_time - processes[0].arrival_time;
processes[0].waiting_time = processes[0].turn_around_time - processes[0].burst_time;
total_waiting_time = processes[0].waiting_time;
total_turn_around_time = processes[0].turn_around_time;
total_waiting_time += processes[i].waiting_time;
// Display results
printf("\nProcess ID\tArrival Time\tBurst Time\tCompletion Time\tTurnaround
Time\tWaiting Time\n");
for (int i = 0; i < n; i++) {
printf("%d\t\t%d\t\t%d\t\t%d\t\t%d\t\t%d\n", processes[i].process_id,
processes[i].arrival_time, processes[i].burst_time, processes[i].completion_time,
processes[i].turn_around_time, processes[i].waiting_time);
}
int main() {
int n;
// Input the number of processes
printf("Enter the number of processes: ");
scanf("%d", &n);
// Dynamically allocate memory for processes
Process *processes = (Process *)malloc(n * sizeof(Process));
if (processes == NULL) {
printf("Memory allocation failed!\n");
return 1; // Exit if memory allocation fails
}
// Input process details (ID, Arrival time, Burst time)
for (int i = 0; i < n; i++) {
processes[i].process_id = i + 1;
printf("\nEnter details for Process %d\n", processes[i].process_id);
printf("Arrival Time: ");
scanf("%d", &processes[i].arrival_time);
printf("Burst Time: ");
EXPERIMENTAL RESULTS/OUTPUTS
TEST CASES
CONCLUSION
REFERENCES
Zorn B., July 1993, The measured cost of conservative garbage collection, SoftwarePractıce
And Experıence, Vol. 23, No. 7, 733-756
Shen. K.K. and Peterson, J.L., Oct. 1974, A weighted buddy method for dynamic storage
allocation. Communications Of The ACM 17, 10, 558-562
Barkle, R.E. ve Lee T.P., Dec 1989, A Lazy Buddy System Bounded by Two Coalescing Delays
per Class, Proc. 12th Symp. OpertatınSystem Prıncples, vol:23, no:5, 167-176
Hırschberg, D.S., Oct. 1973, A class of dynamic memory allocation algorithms.
Communications Of The ACM 16, 10, 615-618
Tanenbaum A.S. ve Woodhull A. S., 1997, Operating Systems Design and Implementation,
Prentice Hall, Portland, 0-13-638677-6
Wilson P. R., Johnstone M. S., Neely M. ve Boles D., September 1995, Dynamic Storage
Allocation: A Survey and Critical Review, International Workshop on Memory
Management, Kinross, Scotland, UK
Peterson J.L. ve Norman T.A., June 1977, Buddy systems, Communications Of The ACM, Vol.
20, 421-431