0% found this document useful (0 votes)
8 views

os project 2

The document is a lab project report on 'Dynamic Memory Allocator' submitted by students of Joginpally B.R. Engineering College for their Bachelor of Technology in Information Technology. It discusses the principles of dynamic memory allocation, including memory management techniques, fragmentation issues, and various allocation strategies such as linked lists and buddy systems. The report emphasizes the importance of efficient memory management for system performance and outlines future advancements in the field.

Uploaded by

Jagadeesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

os project 2

The document is a lab project report on 'Dynamic Memory Allocator' submitted by students of Joginpally B.R. Engineering College for their Bachelor of Technology in Information Technology. It discusses the principles of dynamic memory allocation, including memory management techniques, fragmentation issues, and various allocation strategies such as linked lists and buddy systems. The report emphasizes the importance of efficient memory management for system performance and outlines future advancements in the field.

Uploaded by

Jagadeesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

A Lab Project Report On

DYNAMIC MEMORY ALLOCATOR


Is Submitted to Joginpally BR Engineering College (UGC Autonomous) , Hyderabad. In partial fulfillment
of the requirements for the award of the degree of

BACHELOR OF TECHNOLOGY

IN
INFORMATION TECHNOLOGY

SUBMITTED

Ch Mani Deekshith (23J21A1211)


J Ananth Kumar (23J21A1216)
P Jaya Prakash (23J21A1237)

Under the guidance of


Dr. SHAIK ALEEM BASHA M.Tech,Ph.D
Associate Professor

DEPARTMENT OF INFORMATION TECHNOLOGY

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.

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.

Ch Mani Deekshith (23J21A1211)


J Ananth kumar (23J21A1216)
P Jaya Prakash (23J21A1237)

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

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.

Ch Mani Deekshith (23J21A1211)


J Ananth kumar (23J21A1216)
P Jaya Prakash (23J21A1237)

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

ABSTRACT

A Dynamic Memory Allocator is a system component responsible for managing memory


allocation and deallocation during program execution. Unlike static memory allocation, which
assigns fixed memory at compile time, dynamic memory allocation enables efficient and
flexible memory utilization at runtime. This is particularly useful in applications with
unpredictable memory requirements, such as operating systems, embedded systems, and high-
performance computing.
This paper discusses the fundamental principles of dynamic memory allocation, including heap
management, fragmentation, and garbage collection techniques. It explores common
implementations like malloc/free, buddy system, slab allocation, and memory pools, analyzing
their advantages and trade-offs. Performance optimization strategies such as best-fit, first-fit,
and worst-fit algorithms are also examined.
Efficient memory management is crucial for system performance, reducing memory
fragmentation, and improving execution speed. Future advancements in dynamic memory
allocation involve hardware-assisted techniques, intelligent compaction methods, and machine
learning-based predictive allocation.
This study provides insights into the design and implementation of dynamic memory allocators,
highlighting challenges and solutions for optimized memory management in modern
computing systems.

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

CONTENTS

1. COVER PAGE

ABSTRACT

2. INTRODUCTION

2.1 BASIC CONCEPTS ON DYNAMIC MEMORY ALLOCATION

2.1.1 FRAGMENTATION

2.1.2 INTERNAL FRAGMENTATION

2.1.3 EXTERNAL FRAGMENTATION

2.1.4 TOTAL FRAGMENTATION

2.2 EXECUTING TIME

3 MEMORY ALLOCATION TECHNIQUES

3.1 LINKED LIST TECHNIQUES

3.1.1 FIRST FIT

3.1.2 NEXT FIT

3.1.3 BEST FIT

3.1.4 WORST FIT

3.2 BUDDY SYSTEM

3.2.1 BINARY BUDDY SYSTEM

3.2.2 FIBONACCI BUDDY SYSTEM

3.2.3 WEIGHTED BUDDY SYSTEM


4 SIMULATION AND PERFORMANCE ANALYSIS
5 CODE

6 TEST CASE
7 EXPERIMENTAL RESULTS
8 CONCLUSION
9 REFERENCE

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

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.

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

In computer systems, memory management plays a crucial role in ensuring efficient


and reliable operation. Dynamic memory allocation is a technique that enables programs to
allocate and manage memory at runtime, allowing for flexible and efficient use of system
resources. A dynamic memory allocator is a software component responsible for managing the
allocation and deallocation of memory blocks, ensuring that memory is used efficiently and
minimizing memory-related errors.

Background

Dynamic memory allocation involves allocating memory blocks of varying sizes


from a larger memory pool. The allocator must ensure that memory blocks are allocated
efficiently, minimizing fragmentation and reducing the risk of memory-related errors. Dynamic
memory allocators are used in a wide range of applications, from operating systems and
embedded systems to high-performance computing and cloud computing.

Importance of Dynamic Memory Allocation

Dynamic memory allocation is essential for several reasons:

1. Efficient Memory Use: Dynamic memory allocation enables programs to allocate memory
only when needed, reducing memory waste and improving overall system efficiency.

2. Flexibility: Dynamic memory allocation allows programs to allocate memory blocks of


varying sizes, enabling flexible and efficient memory management.

3. Reliability: Dynamic memory allocation helps minimize memory-related errors, such as


memory leaks and buffer overflows.

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

BASIC CONCEPT OF DYNAMIC MEMORY ALLOCATION


The goal of allocator design is usually to minimize wasted space without undue time cost. An
allocator must keep track of which parts of memory are in use and which parts are free. A
conventional allocator can not control the number or size of live blocks. A conventional
allocator also can not compact memory, moving blocks to make them contiguous. It must
respond immediately to a request for space deciding which block of memory to allocate. It can
only deal with memory whether it is free and only choose where in free memory to allocate the
requested block

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].

2.1.1. Internal Fragmentation


Unless the set of requested block sizes is a subset of the set of provided block sizes, it will be
necessary to allocate more memory space than requested block size. The memory wasted due
to this overallocation is internal fragmentation. Measure of internal fragmentation is the ratio
of number of overallocated blocks to number of allocated memory.

2.1.2. External fragmentation


External fragmentation happens when available free blocks at memory are too numerous and
small and can not be used to allocate next requests for larger blocks. Measure of external
fragmentation is the proportion of total memory which is available when overflow occurs [7].

2.1.3. Total fragmentation


Internal and external fragmentation are an expected result of different properties of the methods
used in memory allocation. But, both decrease the effective size of available memory due to
creation of memory portions that can not be used. We define total fragmentation to be total
amount of memory which is unusable due to either internal or external fragmentation. Since

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE
our definition of internal fragmentation is the propotion of allocated memory which is
unusable, while external fragmentation is a proportion of total memory, total fragmentation is
not simple sum of internal and external fragmentation, but rather calculated as,

total =(1− External)*Internal+ External (3) total = Internal+ External−(Internal*External)

2.2. COALESCING SPLITTING AND


The allocator may split large blocks into smaller blocks to satisfy the request. The remainders
from this splitting can be used to satisfy future requests. The allocator also coalesces adjacent
free blocks to yield larger free blocks. After a block is freed, the allocator may check to see
whether neighboring blocks are free and merge them into a single, larger block. Splitting and
coalescing processes must be done to decrease fragmentation problem.

2.3. EXECUTING TIME


Another performance criteria in memory allocation is execution time (allocation and
deallocatin duration). Splitting and coalescing performed for decreasing fragmentation
increases the running time. In general, running time is inversely proportional to fragmentation.

3. MEMORY ALLOCATION TECHNIQUES


Very different techniques are developed to combat fragmentation. Although, some of them
decrease external fragmentation, the others solve internal fragmentation. But, there is not yet
any mechanism to solve this problem perfectly. The basic allocation mechanisms are separated
into 3 categories [5]:

• Bitmap
• Linked List techniques: First Fit, Best Fit, Next Fit, Worst Fit
• Buddy Systems: Binary, Fibonacci,
Weighted

3.1. BIT MAP TECHNIQUE


The fundamental of Bitmap technique is that status of each blocks in memory is represented
with a bit in Bit map which is 0 if the block is free and 1 if it is allocated. Figure 1 shows part

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE
of the memory and the corresponding bit map. The smaller the allocation unit, the larger the
bitmap.

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

3.2. LINKED LIST TECHNIQUES


Memory management techniques by using Linked lists is the most used technique. These
techniques allocate by using linked list structure.

Linked list techniques used more frequently are;

• First Fit: Allocate the first hole that is big enough.


• Next Fit: Allocate the first hole that is big enough starting where it left off.
• Best fit: Allocate the smallest hole that is big enough.
• Worst Fit: Allocate the largest hole

3.2.1. First Fit


The memory manager starts to scan from beginning of the lists until it finds a hole that is big
enough. The hole is then broken up into two pieces, one for the process and one for the unused
memory. A problem with first fit is that the larger blocks near the beginning of the list tend to

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE
be split first and the remaining fragments result in having a lot of small blocks near the
beginning of the list. These small memory blocks can increase search times. Because many
small free blocks accumulate and the search must go through them each time a larger block is
requested.

3.2.2. Next Fit


The greatest difference of this technique from others is that search starts always different place
of the list. The pointer records the position where the last search was satisfied and the next
search begins from there. By means of this feature, Small and awkward memory hole can not
accumulate at the beginning of the list as first fit technique

3.2.3. Best Fit


A best fit allocator searches the list to find smallest free blocks large enough to satisfy a request
and then allocate this blocks. Best fit is slower than first fit and next fit. Because it must search
the entire list every time it is called.

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.

3.2.4. Worst Fit


Working manner of this technique is more similar to best fit. Difference between them is that
while best fit select the smallest hole, worst fit take the largest available hole. This strategy

Figure 2:sample representation of linked lists


(a) a part of memory (b) Corresponding linked
list

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE
produces the largest leftover hole, which may be more useful than the smaller leftover from a
best fit approach.

3.3. BUDDY SYSTEMS


Important property for the buddy systems over first fit or best fit memory management schemes
was its reduction in search time to find and allocate an available block of appropriate size. By
means of using tree structure, finding appropriate hole is performed faster.

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.

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE
Figure 3: Tree structure of Binary Buddy

System

.3.2. Fibonacci Buddy System


In this system, blocks are split in respect of Fibonacci numbers. Working mechanism of it is
similar to binary buddy system. Fibonacci series are defined as follows.

F0 =0,F1 =1,Fn+2 =Fn+1 +Fn(n≥0)

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...

Figure 4 shows sample tree structure of Fibonacci Buddy systems.

Figure 4: Tree structure of Fibonacci Buddy system

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)].

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

Figure 5: (a) Splitting of 2k+2 block size (b)

Splitting of 3*2k+2 block size

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.

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE
Allocation and deallocation process can not be calculated sensitively by using classic time
function in C++. Because, running time implements in very short time. In order to solve this
problem, Windows API

“QueryPerformanceFrequency” is used. By this API, each allocation and deallocation duration


and their average are calculated in the micro second type. Program is run 100 times for
obtaining more realistic results.

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.

binary internal weighted internal


binary external weighted external
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
1024- 1024- 1024- 512- 512- 512- 256- 256- 256-
256 128 64 128 64 32 64 32 16

Memory size- Max. object size

Figure 7: Internal and External fragmentation of

Buddy Systems

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE
In figure 8, In respect of fragmentation criteria, First fit is the best and Binary buddy is the
worst technique. Allocation of bit map method gives close similarity to first fit. Because,
searching bits is performed as first fit.

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

bitmap by inverting (from 1 to 0) all bits corresponding deallocated blocks.

Firt Fit Bit Map Binary Buddy

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

Memory Size - Max. Object Size

Figur 8: Total fragmentation values of techniques

Firt Fit Bit Map Binary Buddy

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

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

Memory Size - Max. Object Size

Figure 9: Allocation duration of techniques

(micro second)

Worst Fit Bit Map Binary Buddy

3.5

2.5

1.5 1024- 1024- 1024- 512- 512- 512- 256-


1 256 128 64 128 64 32 64
256- 256-
0.5 0 Memory Size - Max. Object Size 32 16

Figure 10: Deallocation duration of techniques

CODE

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

#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;

// Function to calculate and display waiting and turn-around times


void calculateTimes(Process *processes, int n) {
int total_waiting_time = 0;
int total_turn_around_time = 0;

// 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;

for (int i = 1; i < n; i++) {


processes[i].completion_time = processes[i-1].completion_time +
processes[i].burst_time;
processes[i].turn_around_time = processes[i].completion_time -
processes[i].arrival_time;
processes[i].waiting_time = processes[i].turn_around_time - processes[i].burst_time;

total_waiting_time += processes[i].waiting_time;

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE
total_turn_around_time += processes[i].turn_around_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);
}

printf("\nAverage Waiting Time: %.2f\n", (float)total_waiting_time / n);


printf("Average Turnaround Time: %.2f\n", (float)total_turn_around_time / n);
}

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: ");

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE
scanf("%d", &processes[i].burst_time);
}
// Call the function to calculate and display times
calculateTimes(processes, n);
// Free the dynamically allocated memory
free(processes);
return 0;
}

EXPERIMENTAL RESULTS/OUTPUTS

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

TEST CASES

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

CONCLUSION

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

In this paper, Performance analysis of examined memory allocation techniques is performed


comparatively in respect of performance criteria.
The performance analysis of examined memory allocation techniques, a Simulator is written in
C++ programming language. 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 methods classified categorically is evaluated. Despite First Fit
listing technique shows better performance according to fragmentation, it can not show the
same success in respect of allocation and deallocation time. Binary buddy is very fast but it
has the worst at fragmentation rate. According to these results, it is seen that there are not yet
the best performance techniques point from all performance criteria.
Consequently, it can not be said that the basic memory allocation techniques are successful. To
minimize the fragmentation problem and to allocate faster, new memory allocation techniques
can be implemented by using hardware structure.
It is suggested that by using new and different data structures, faster and more efficient memory
allocators can be achieved.

REFERENCES

DYNAMIC MEMORY ALLOCATOR


JOGINPALLY B.R. ENGINEERING COLLEGE

 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

DYNAMIC MEMORY ALLOCATOR

You might also like