SlideShare a Scribd company logo
1 of 7
DEPARTMENT OF COMPUTER SCIENCE &
ENGG.
Presented By: Bhimsen D Joshi
Lecturer/CSE
B.L.D.E.A’S S.S.M. POLYTECHNIC
VIJAYAPUR
B.L.D.E.A’S S.S.M
POLYTECHNIC VIJAYAPUR
SEMINAR ON DYNAMIC
MEMORY MANAGEMENT
INTRODUCTION
The process of allocating memory at runtime is
known as dynamic memory allocation.
Dynamic memory allocation can be made using 4 functions
of stdlib.h header file.
malloc()
calloc()
realloc()
free()
Static Memory Allocation Dynamic Memory Allocation
Memory is allocated during
compile time.
Memory is allocated at run time.
Memory cannot be increased at
program execution time.
Memory can be increased at the
program execution time.
Array uses static allocation. Linked list uses dynamic allocation.
Dynamic memory allocation functions listed below.
Function Name Syntax
malloc() malloc (number *sizeof(int));
calloc() calloc (number, sizeof(int));
realloc() realloc (pointer_name, number *
sizeof(int));
free() free (pointer_name);
Function Name Description
malloc() allocates single block of memory.
calloc() allocates multiple block of memory.
realloc() reallocates the memory allocated by
malloc() or calloc() functions.
free() frees the allocated memory.
int *p;
p = (int*)malloc(1 * sizeof(int)); //memory space allocated to variable p
int *r;
r= (int*)calloc(1,2); //memory space allocated to variable r
int *p;
p = (int*)malloc(5 * sizeof(int));
p = (int*)reallc(p,10); //allocated a new memory to variable p
free(p);
SHORT EXAMPLES
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
main()
{
int *p,*r;
clrscr();
p = (int*)malloc(1*sizeof(int));
/* allocates memory block for storing an integer and block starting address store in a pointer p*/
*p=20; /* The value 20 stored in a block */
printf("nThe Value Stored in p is %d",*p);
r = (int*)calloc(1,2);
/* allocates memory block for storing an integer and block starting address store in a pointer r */
*r=40; /* The value 40 stored in a block */
printf("nThe Value Stored in r is %d",*r);
p = (int*)realloc(p,2); /* reallocates memory blocks for storing 2 integer values */
p[1]=25;
printf(“nP Block values are %d %d",p[0],p[1]);
free(p);
getch();
}
A COMPLETE EXAMPLE TO SHOW MEMORY ALLOCATION
FUNCTIONS.
4000 5000
20
40
20 25
p r
p
0 1
4000 4002
4000
2000 3000
5000
4000
Presentation on dynamic memory management
Presentation on dynamic memory management

More Related Content

Similar to Presentation on dynamic memory management

Dynamic Memory Allocation In C
Dynamic Memory Allocation In CDynamic Memory Allocation In C
Dynamic Memory Allocation In C
Simplilearn
 

Similar to Presentation on dynamic memory management (20)

Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
Dma
DmaDma
Dma
 
Memory Allocation & Direct Memory Allocation in C & C++ Language PPT
Memory Allocation & Direct Memory Allocation in C & C++ Language PPTMemory Allocation & Direct Memory Allocation in C & C++ Language PPT
Memory Allocation & Direct Memory Allocation in C & C++ Language PPT
 
Dynamic Memory Allocation
Dynamic Memory AllocationDynamic Memory Allocation
Dynamic Memory Allocation
 
Dynamic Memory Allocation, Pointers and Functions, Pointers and Structures
Dynamic Memory Allocation, Pointers and Functions, Pointers and StructuresDynamic Memory Allocation, Pointers and Functions, Pointers and Structures
Dynamic Memory Allocation, Pointers and Functions, Pointers and Structures
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Introduction to Data Structures, Data Structures using C.pptx
Introduction to Data Structures, Data Structures using C.pptxIntroduction to Data Structures, Data Structures using C.pptx
Introduction to Data Structures, Data Structures using C.pptx
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c language
 
Dynamic Memory Allocation in C
Dynamic Memory Allocation in CDynamic Memory Allocation in C
Dynamic Memory Allocation in C
 
Lec05 buffers basic_examples
Lec05 buffers basic_examplesLec05 buffers basic_examples
Lec05 buffers basic_examples
 
Linux memorymanagement
Linux memorymanagementLinux memorymanagement
Linux memorymanagement
 
dynamicmemoryallocation.pptx
dynamicmemoryallocation.pptxdynamicmemoryallocation.pptx
dynamicmemoryallocation.pptx
 
Functions with heap and stack....by thanveer danish
Functions with heap and stack....by thanveer danishFunctions with heap and stack....by thanveer danish
Functions with heap and stack....by thanveer danish
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Dynamic Memory Allocation In C
Dynamic Memory Allocation In CDynamic Memory Allocation In C
Dynamic Memory Allocation In C
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
C interview questions
C interview questionsC interview questions
C interview questions
 

Recently uploaded

Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
Kira Dess
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
drjose256
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
MaherOthman7
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
benjamincojr
 

Recently uploaded (20)

What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Students
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
Intro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney UniIntro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney Uni
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdf
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Station
 
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
Tembisa Central Terminating Pills +27838792658 PHOMOLONG Top Abortion Pills F...
 
21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
15-Minute City: A Completely New Horizon
15-Minute City: A Completely New Horizon15-Minute City: A Completely New Horizon
15-Minute City: A Completely New Horizon
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
 

Presentation on dynamic memory management

  • 1. DEPARTMENT OF COMPUTER SCIENCE & ENGG. Presented By: Bhimsen D Joshi Lecturer/CSE B.L.D.E.A’S S.S.M. POLYTECHNIC VIJAYAPUR B.L.D.E.A’S S.S.M POLYTECHNIC VIJAYAPUR SEMINAR ON DYNAMIC MEMORY MANAGEMENT
  • 2. INTRODUCTION The process of allocating memory at runtime is known as dynamic memory allocation. Dynamic memory allocation can be made using 4 functions of stdlib.h header file. malloc() calloc() realloc() free()
  • 3. Static Memory Allocation Dynamic Memory Allocation Memory is allocated during compile time. Memory is allocated at run time. Memory cannot be increased at program execution time. Memory can be increased at the program execution time. Array uses static allocation. Linked list uses dynamic allocation. Dynamic memory allocation functions listed below. Function Name Syntax malloc() malloc (number *sizeof(int)); calloc() calloc (number, sizeof(int)); realloc() realloc (pointer_name, number * sizeof(int)); free() free (pointer_name);
  • 4. Function Name Description malloc() allocates single block of memory. calloc() allocates multiple block of memory. realloc() reallocates the memory allocated by malloc() or calloc() functions. free() frees the allocated memory. int *p; p = (int*)malloc(1 * sizeof(int)); //memory space allocated to variable p int *r; r= (int*)calloc(1,2); //memory space allocated to variable r int *p; p = (int*)malloc(5 * sizeof(int)); p = (int*)reallc(p,10); //allocated a new memory to variable p free(p); SHORT EXAMPLES
  • 5. #include<stdio.h> #include<stdlib.h> #include<conio.h> main() { int *p,*r; clrscr(); p = (int*)malloc(1*sizeof(int)); /* allocates memory block for storing an integer and block starting address store in a pointer p*/ *p=20; /* The value 20 stored in a block */ printf("nThe Value Stored in p is %d",*p); r = (int*)calloc(1,2); /* allocates memory block for storing an integer and block starting address store in a pointer r */ *r=40; /* The value 40 stored in a block */ printf("nThe Value Stored in r is %d",*r); p = (int*)realloc(p,2); /* reallocates memory blocks for storing 2 integer values */ p[1]=25; printf(“nP Block values are %d %d",p[0],p[1]); free(p); getch(); } A COMPLETE EXAMPLE TO SHOW MEMORY ALLOCATION FUNCTIONS. 4000 5000 20 40 20 25 p r p 0 1 4000 4002 4000 2000 3000 5000 4000