SlideShare a Scribd company logo
1 of 15
By,
A.Amalajoylet
(25’Aug 2016)
Types of memory allocation
Why DMA ???
Intro to DMA
Four library functions
Memory allocation process
Mallolc()
Calloc()
realloc()
free()
 Static memory allocation :
Done implicitly by the programmer
before execution.
 Dynamic memory allocation :
Done explicitly by the programmer
durind the run time.
 Problem with Arrays:
 C requires the no. of elements in an array to be
specified at compile time.
 It is difficult to know the exact size of the array
in advance (prior to execution).
 If the size needed at run time is small than the
specified size, then we have wastage of memory
space.
 If the size needed at run time is greater than the
specified size, we will have shortage of memory
space.
 Solution: DMA
 The process of allocating and freeing
memory at run time (or execution time) is
called dynamic memory allocation.
 Although c does not inherently have this
facility there are four library routines
which can be used to allocate and free
memory during the program execution.
 In C we have the following four functions for
memory management process:
 malloc()
 calloc()
 realloc()
 free()
 These are defined in header file stdlib.h
7
 It allocates requested size of bytes and
returns a pointer to the first byte of the
allocated space.
 Syntax:
p=(data_type *)malloc(size_of_block);
 E.g.
x=(int*)malloc(100*sizeof(int));
x=(int *)malloc(200);
void main()
{
int i, n, *ptr;
scanf(“%d”, &n);
ptr = (int *) malloc( n* sizeof(int) );
for(i=0;i<n;i++)
{
scanf(“%d”, ptr+i );
}
for(i=0;i<n;i++)
{
printf(“ %d ”, *(ptr+i) );
}
}
 Unlike malloc(),calloc() accepts two
arguments: no_of_blocks and size_of_each_block
so,that calloc() can allocate memory for an array of
elements.
 All bytes allocated using calloc() are initialized
to zero and a pointer to the first byte is returned.
 Syntax:
p=(data_type*)calloc(no_of_blocks,size_of_each_block);
 E.g. x=(int *)calloc(5, 100*sizeof(int));
void main()
{
int i, n, *ptr;
scanf(“%d”, &n);
ptr = (int *) calloc( n , sizeof(int) );
for(i=0;i<n;i++)
{
scanf(“%d”, ptr+i );
}
for(i=0;i<n;i++)
{
printf(“ %d ”, *(ptr+i) );
}
}
 It is used to modify the size of the
previously allocated space.
 Syntax:
If original allocation has been done as:
p=(data_type *)malloc(size);
then reallocation is done as:
p=(data_type*)realloc(p, new_size);
 It frees previously allocated memory space
by malloc(), calloc(), or realloc() function.
 Syntax: free(pointer_name);
THANK YOU

More Related Content

What's hot

13. dynamic allocation
13. dynamic allocation13. dynamic allocation
13. dynamic allocation
웅식 전
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
Srikanth
 

What's hot (20)

Dynamic Memory Allocation
Dynamic Memory AllocationDynamic Memory Allocation
Dynamic Memory Allocation
 
13. dynamic allocation
13. dynamic allocation13. dynamic allocation
13. dynamic allocation
 
Intoduction to dynamic memory allocation
Intoduction to dynamic memory allocationIntoduction to dynamic memory allocation
Intoduction to dynamic memory allocation
 
C dynamic ppt
C dynamic pptC dynamic ppt
C dynamic ppt
 
Stack and heap
Stack and heapStack and heap
Stack and heap
 
Standard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented ProgrammingStandard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented Programming
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning Programmers
 
Numpy Talk at SIAM
Numpy Talk at SIAMNumpy Talk at SIAM
Numpy Talk at SIAM
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
NUMPY
NUMPY NUMPY
NUMPY
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & Matplotlib
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
Tensor flow (1)
Tensor flow (1)Tensor flow (1)
Tensor flow (1)
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
 
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMYComputer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
 
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuanScientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
 
Scala user-group-19.03.2014
Scala user-group-19.03.2014Scala user-group-19.03.2014
Scala user-group-19.03.2014
 
Faster Python, FOSDEM
Faster Python, FOSDEMFaster Python, FOSDEM
Faster Python, FOSDEM
 

Viewers also liked (17)

veronica
    veronica    veronica
veronica
 
Refleksi
RefleksiRefleksi
Refleksi
 
Pointers
PointersPointers
Pointers
 
Kbat2
Kbat2Kbat2
Kbat2
 
Membaiki pakaian
Membaiki pakaianMembaiki pakaian
Membaiki pakaian
 
Rbt3120 murni gold course modul jahitan & pertanian
Rbt3120   murni gold course modul jahitan & pertanianRbt3120   murni gold course modul jahitan & pertanian
Rbt3120 murni gold course modul jahitan & pertanian
 
Saturday
SaturdaySaturday
Saturday
 
Notapoket sn t4edit
Notapoket sn t4editNotapoket sn t4edit
Notapoket sn t4edit
 
Eco
Eco Eco
Eco
 
Storage class
Storage classStorage class
Storage class
 
Apa itu pengajaran makro
Apa itu pengajaran makroApa itu pengajaran makro
Apa itu pengajaran makro
 
Apa itu pentaksiran berasaskan sekolah sejarah
Apa itu pentaksiran berasaskan sekolah  sejarahApa itu pentaksiran berasaskan sekolah  sejarah
Apa itu pentaksiran berasaskan sekolah sejarah
 
Rencana
RencanaRencana
Rencana
 
Rph sejarah sem 6
Rph sejarah sem 6Rph sejarah sem 6
Rph sejarah sem 6
 
Folio jahitan
Folio jahitanFolio jahitan
Folio jahitan
 
S4 tarea4 paran
S4 tarea4 paranS4 tarea4 paran
S4 tarea4 paran
 
Bengkel skor a bahagian b 2015
Bengkel skor a bahagian b 2015Bengkel skor a bahagian b 2015
Bengkel skor a bahagian b 2015
 

Similar to Dma

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

Similar to Dma (20)

Dynamic Memory Allocation in C
Dynamic Memory Allocation in CDynamic Memory Allocation in C
Dynamic Memory Allocation in C
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
Memory management CP
Memory management  CPMemory management  CP
Memory management CP
 
Introduction to c part -3
Introduction to c   part -3Introduction to c   part -3
Introduction to c part -3
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
dynamicmemoryallocation.pptx
dynamicmemoryallocation.pptxdynamicmemoryallocation.pptx
dynamicmemoryallocation.pptx
 
DYNAMIC MEMORY ALLOCATION.pptx
DYNAMIC MEMORY ALLOCATION.pptxDYNAMIC MEMORY ALLOCATION.pptx
DYNAMIC MEMORY ALLOCATION.pptx
 
DYNAMIC MEMORY ALLOCATION.pptx
DYNAMIC MEMORY ALLOCATION.pptxDYNAMIC MEMORY ALLOCATION.pptx
DYNAMIC MEMORY ALLOCATION.pptx
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic 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
 
C interview questions
C interview questionsC interview questions
C interview questions
 
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
 
Data Structure - Dynamic Memory Allocation
Data Structure - Dynamic Memory AllocationData Structure - Dynamic Memory Allocation
Data Structure - Dynamic Memory Allocation
 
dynamic_v1-3.pptx
dynamic_v1-3.pptxdynamic_v1-3.pptx
dynamic_v1-3.pptx
 
dynamic-allocation.pdf
dynamic-allocation.pdfdynamic-allocation.pdf
dynamic-allocation.pdf
 
15 Jo P Mar 08
15 Jo P Mar 0815 Jo P Mar 08
15 Jo P Mar 08
 
Stack & heap
Stack & heap Stack & heap
Stack & heap
 
Dma
DmaDma
Dma
 
Memory Management.pptx
Memory Management.pptxMemory Management.pptx
Memory Management.pptx
 

Recently uploaded

Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
hublikarsn
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 

Dma

  • 2. Types of memory allocation Why DMA ??? Intro to DMA Four library functions Memory allocation process Mallolc() Calloc() realloc() free()
  • 3.  Static memory allocation : Done implicitly by the programmer before execution.  Dynamic memory allocation : Done explicitly by the programmer durind the run time.
  • 4.  Problem with Arrays:  C requires the no. of elements in an array to be specified at compile time.  It is difficult to know the exact size of the array in advance (prior to execution).  If the size needed at run time is small than the specified size, then we have wastage of memory space.  If the size needed at run time is greater than the specified size, we will have shortage of memory space.  Solution: DMA
  • 5.  The process of allocating and freeing memory at run time (or execution time) is called dynamic memory allocation.  Although c does not inherently have this facility there are four library routines which can be used to allocate and free memory during the program execution.
  • 6.  In C we have the following four functions for memory management process:  malloc()  calloc()  realloc()  free()  These are defined in header file stdlib.h
  • 7. 7
  • 8.  It allocates requested size of bytes and returns a pointer to the first byte of the allocated space.  Syntax: p=(data_type *)malloc(size_of_block);  E.g. x=(int*)malloc(100*sizeof(int)); x=(int *)malloc(200);
  • 9. void main() { int i, n, *ptr; scanf(“%d”, &n); ptr = (int *) malloc( n* sizeof(int) ); for(i=0;i<n;i++) { scanf(“%d”, ptr+i ); } for(i=0;i<n;i++) { printf(“ %d ”, *(ptr+i) ); } }
  • 10.  Unlike malloc(),calloc() accepts two arguments: no_of_blocks and size_of_each_block so,that calloc() can allocate memory for an array of elements.  All bytes allocated using calloc() are initialized to zero and a pointer to the first byte is returned.  Syntax: p=(data_type*)calloc(no_of_blocks,size_of_each_block);  E.g. x=(int *)calloc(5, 100*sizeof(int));
  • 11. void main() { int i, n, *ptr; scanf(“%d”, &n); ptr = (int *) calloc( n , sizeof(int) ); for(i=0;i<n;i++) { scanf(“%d”, ptr+i ); } for(i=0;i<n;i++) { printf(“ %d ”, *(ptr+i) ); } }
  • 12.  It is used to modify the size of the previously allocated space.  Syntax: If original allocation has been done as: p=(data_type *)malloc(size); then reallocation is done as: p=(data_type*)realloc(p, new_size);
  • 13.
  • 14.  It frees previously allocated memory space by malloc(), calloc(), or realloc() function.  Syntax: free(pointer_name);