SlideShare a Scribd company logo
1 of 25
DISCOVER . LEARN . EMPOWER
Topic : DMA
INSTITUTE - UIE
DEPARTMENT- ACADEMIC UNIT-2
Bachelor of Engineering (Computer Science & Engineering)
Subject Name: Object Oriented Programming using C++
Code:20CST151
Unit-3
Object Oriented
Programming
using C++
Course Objectives
2
• To enable the students to understand various stages and constructs
of C++ programming language and relate them to engineering
programming problems.
• To improve their ability to analyze and address variety of problems in
programming domains.
3
CO
Number
Title Level
CO1 Provide the environment that allows students to
understand object-oriented programming Concepts.
Understand
CO2 Demonstrate basic experimental skills for differentiating
between object-oriented and procedural programming
paradigms and the advantages of object-oriented
programs.
Remember
CO3 Demonstrate their coding skill on complex programming
concepts and use it for generating solutions for
engineering and mathematical problems.
Understand
CO4 Develop skills to understand the application of classes,
objects, constructors, destructors, inheritance, operator
overloading and polymorphism, pointers, virtual
functions, exception handling, file operations and
handling.
Understand
Course Outcomes
Scheme of Evaluation
4
Sr.
No.
Type of Assessment
Task
Weightage of actual
conduct
Frequency of Task Final Weightage in Internal
Assessment (Prorated
Marks)
Remarks
1. Assignment* 10 marks of
each assignment
One Per Unit 10 marks As applicable to
course types depicted
above.
2. Time Bound
Surprise
Test
12 marks for each
test
One per Unit 4 marks As applicable to
course types
depicted above.
3. Quiz 4 marks of each quiz 2 per Unit 4marks As applicable to
course types
depicted above.
4. Mid-Semester Test** 20 marks for one
MST.
2 per semester 20 marks As applicable to
course types
depicted above.
5. Presentation*** Non Graded: Engagement
Task
Only for Self Study
MNGCourses.
6. Homework NA One per lecture topic
(of 2
questions)
Non-Graded: Engagement
Task
As applicable to
course types
depicted above.
7. Discussion Forum NA One per
Chapter
Non Graded: Engagement
Task
As applicable to
course types depicted
above.
8. Attendance and
Engagement Score
on BB
NA NA 2 marks
Why
When amount of memory to be
allocated is not known
beforehand, rather it is
determined at the time of
program run, it is called Dynamic
Memory Allocation. It leads to
efficient utilization of storage
space.
What
Dynamic memory
allocation means creating
memory at runtime. It can
be done with the help of
new operator in CPP.
• Introduction to DMA
• Static Memory Allocation and
Dynamic Memory Allocation
• New and delete operator
6
CONTENTS
Static Memory Allocation
Static memory allocation happens for Static and global variables. Memory for
these types of variables is allocated once when your program is run and persists
throughout the life of your program. When amount of memory to be allocated is
known beforehand i.e. at the time of compilation, it is known as Static Memory
Allocation. Once the memory is allocated statically, it cannot be de-allocated
during program run. So it leads to wastage of storage space. The Stack is used for
static memory allocation.
Example:
int A[100];
7
Dynamic memory allocation
When you dynamically allocate memory, you are asking the operating
system to reserve some of that memory for your program’s use. When
your application is done with the memory, it can return the memory
back to the operating system to be given to another program. Unlike
static, the program itself is responsible for requesting and disposing
of dynamically allocated memory. In CPP this can be done with the
help of new and delete operator. The Heap is used for Dynamic
memory allocation.
8
Dynamic memory allocation
When amount of memory to be allocated is not known beforehand,
rather it is determined at the time of program run, it is called
Dynamic Memory Allocation. It leads to efficient utilization of
storage space. Example:
cout << " Enter number of elements: ";
cin >> N;
int *A = new int[N]; // dynamic memory allocation
9
C++ new operator
Dynamic memory allocation means creating memory at runtime. For
example, when we declare an array, we must provide size of array in
our source code to allocate memory at compile time. But if we need
to allocate memory at runtime must use new operator followed by
data type. If we need to allocate memory for more than one element,
we must provide total number of elements required in square
bracket[ ]. It will return the address of first byte of memory
10
11
ptr = new data-type;
//allocate memory for one element
ptr = new data-type [ size ];
//allocate memory for fixed number of element
Syntax of new operator
12
Delete operator is used to deallocate the memory created by new operator at
run-time. Once the memory is no longer needed it should by freed so that the
memory becomes available again for other request of dynamic memory.
Syntax of delete operator
delete ptr;
//deallocate memory for one element
delete[] ptr;
//deallocate memory for array
C++ Delete operator
Example of c++ new and delete operator
#include<iostream.h>
#include<conio.h>
void main()
{
int size,i;
int *ptr;
cout<<"ntEnter size of Array : ";
cin>>size;
13
14
ptr = new int[size];
//Creating memory at run-time and return first byte of address to ptr.
for(i=0;i<5;i++) //Input array from user.
{
cout<<"nEnter any number : ";
cin>>ptr[i];
}
for(i=0;i<5;i++) //Output arrray to console.
cout<<ptr[i]<<", ";
Example of c++ new and delete operator
Example of c++ new and delete operator
delete[] ptr;
//deallocating all the memory created by new operator
}
Output :
Enter size of Array : 5
Enter any number : 78
Enter any number : 45
Enter any number : 12
Enter any number : 89
Enter any number : 56
78, 45, 12, 89, 56,
15
Use of new and delete operator in class
#include <iostream>
using namespace std;
class Box {
public:
Box() {
cout << "Constructor called!" <<endl;
} ~Box() {
cout << "Destructor called!" <<endl;
}
}; int main() {
Box* myBoxArray = new Box[4];
16
Use of new and delete operator in class
delete [] myBoxArray; // Delete array
return 0;
}
Output is:
Constructor called!
Constructor called!
Constructor called!
Constructor called!
Destructor called!
Destructor called!
Destructor called!
Destructor called! 17
Applications of DMA
• Dynamically Allocated Memory is used to allocate memory of variable
size which is not possible with compiler allocated memory
except variable length arrays.
• Most important use of DMA is flexibility provided to programmers.
We are free to allocate and de-allocate memory whenever we need
and whenever we don’t need anymore. There are many cases where
this flexibility helps. Examples of such cases are linked list ,tree etc.
18
19
Summary
In this lecture we have
discussed about DMA.
We have discussed about Static
and Dynamic memory
allocation.
Discussed about new and
delete operator.
Discussed about new and
delete operator in class.
Frequently Asked question
Q1 What is DMA?
When amount of memory to be allocated is not known beforehand,
rather it is determined at the time of program run, it is called Dynamic
Memory Allocation. It leads to efficient utilization of storage space.
Q2 What is static memory allocation?
When amount of memory to be allocated is known beforehand i.e. at the
the time of compilation, it is known as Static Memory Allocation. Once the
memory is allocated statically, it cannot be deallocated during program run.
So it leads to wastage of storage space.
20
Q3 What is new operator?
New operator is used to allocate memory at runtime .Syntax of new
operator is: ptr = new data-type;
//allocate memory for one element
ptr = new data-type [ size ];
//allocate memory for fixed number of element
Q4 What is delete operator?
Delete operator is used to deallocate the memory created by new operator at
run-time.Syntax of delete operator is
delete ptr;
//deallocate memory for one element
delete[] ptr;
//deallocate memory for array
21
Assessment Questions:
22
1. Which of the following is not a false statement about new operator?
a. It can’t be overloaded.
b. It returns garbage value when memory allocation fails.
c. It automatically computes the size of the data object.
d. All of these
2.Which of the following is/are valid ways to allocate memory for an
integer by dynamic memory allocation in CPP.
a. int *p = new int(100);
b. int *p; p = new int; *p = 100;
c. int *p = NULL; p = new int; *p=100;
d. Only 1,2
e. All of these
Discussion forum.
How can we differ Static memory Allocation and Dynamic Memory
Allocation
How to use new and delete operator ??
23
https://youtu.be/UY2_lLpDu7U
https://youtu.be/sRBB_qX4lKY
REFERENCES
Reference Books
[1] Programming in C++ by Reema Thareja.
[2] Programming in ANSI C++ by E. Balaguruswamy, Tata
McGraw Hill.
[3] Programming with C++ (Schaum's Outline
Series) by Byron Gottfried Jitender Chhabra, Tata McGraw
Hill.
Websites:
• https://www.geeksforgeeks.org/new-and-delete-operators-in-
cpp-for-dynamic-
• https://www.studytonight.com/cpp/memory-management-in-
cpp.php
YouTube Links:
• https://youtu.be/UY2_lLpDu7U
• https://youtu.be/sRBB_qX4lKY
24
THANK YOU

More Related Content

Similar to PPT DMA.pptx

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 StructuresSelvaraj Seerangan
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory ManagementAnil Bapat
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Sameer Rathoud
 
16858 memory management2
16858 memory management216858 memory management2
16858 memory management2Aanand Singh
 
CS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2ndCS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2ndEdward Chen
 
Things you can find in the plan cache
Things you can find in the plan cacheThings you can find in the plan cache
Things you can find in the plan cachesqlserver.co.il
 
Devry gsp 215 week 6 i lab virtual memory new
Devry gsp 215 week 6 i lab virtual memory newDevry gsp 215 week 6 i lab virtual memory new
Devry gsp 215 week 6 i lab virtual memory newwilliamethan912
 
Storage classes, linkage & memory management
Storage classes, linkage & memory managementStorage classes, linkage & memory management
Storage classes, linkage & memory managementMomenMostafa
 
Programming in Java: Why Object-Orientation?
Programming in Java: Why Object-Orientation?Programming in Java: Why Object-Orientation?
Programming in Java: Why Object-Orientation?Martin Chapman
 
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 danishMuhammed Thanveer M
 
PF UE LEC 7 Pointers programming fundamentals (2).pptx
PF UE LEC 7 Pointers programming fundamentals (2).pptxPF UE LEC 7 Pointers programming fundamentals (2).pptx
PF UE LEC 7 Pointers programming fundamentals (2).pptxhelpme43
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and DestructorsKeyur Vadodariya
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
Dma
DmaDma
DmaAcad
 

Similar to PPT DMA.pptx (20)

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
 
16829 memory management2
16829 memory management216829 memory management2
16829 memory management2
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())
 
16858 memory management2
16858 memory management216858 memory management2
16858 memory management2
 
CS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2ndCS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2nd
 
Pointer
PointerPointer
Pointer
 
Dynamic Memory Allocation in C
Dynamic Memory Allocation in CDynamic Memory Allocation in C
Dynamic Memory Allocation in C
 
Things you can find in the plan cache
Things you can find in the plan cacheThings you can find in the plan cache
Things you can find in the plan cache
 
Devry gsp 215 week 6 i lab virtual memory new
Devry gsp 215 week 6 i lab virtual memory newDevry gsp 215 week 6 i lab virtual memory new
Devry gsp 215 week 6 i lab virtual memory new
 
Memory management
Memory managementMemory management
Memory management
 
Storage classes, linkage & memory management
Storage classes, linkage & memory managementStorage classes, linkage & memory management
Storage classes, linkage & memory management
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
Programming in Java: Why Object-Orientation?
Programming in Java: Why Object-Orientation?Programming in Java: Why Object-Orientation?
Programming in Java: Why Object-Orientation?
 
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
 
PF UE LEC 7 Pointers programming fundamentals (2).pptx
PF UE LEC 7 Pointers programming fundamentals (2).pptxPF UE LEC 7 Pointers programming fundamentals (2).pptx
PF UE LEC 7 Pointers programming fundamentals (2).pptx
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
final GROUP 4.pptx
final GROUP 4.pptxfinal GROUP 4.pptx
final GROUP 4.pptx
 
Dma
DmaDma
Dma
 

More from Abhishekkumarsingh630054

More from Abhishekkumarsingh630054 (7)

UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
 
lecture 10 Recursive Function and Macros.ppt
lecture 10 Recursive Function and Macros.pptlecture 10 Recursive Function and Macros.ppt
lecture 10 Recursive Function and Macros.ppt
 
NIFT-Sample-Paper-2020-btech-Programme-GAT.pdf
NIFT-Sample-Paper-2020-btech-Programme-GAT.pdfNIFT-Sample-Paper-2020-btech-Programme-GAT.pdf
NIFT-Sample-Paper-2020-btech-Programme-GAT.pdf
 
7. Pointers and Virtual functions final -3.pptx
7. Pointers and Virtual functions final -3.pptx7. Pointers and Virtual functions final -3.pptx
7. Pointers and Virtual functions final -3.pptx
 
Chapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptxChapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptx
 
DT-2 Exp 2.3_2.pdf
DT-2 Exp 2.3_2.pdfDT-2 Exp 2.3_2.pdf
DT-2 Exp 2.3_2.pdf
 
ar vr mr certificate.pdf
ar vr mr certificate.pdfar vr mr certificate.pdf
ar vr mr certificate.pdf
 

Recently uploaded

Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 

Recently uploaded (20)

Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 

PPT DMA.pptx

  • 1. DISCOVER . LEARN . EMPOWER Topic : DMA INSTITUTE - UIE DEPARTMENT- ACADEMIC UNIT-2 Bachelor of Engineering (Computer Science & Engineering) Subject Name: Object Oriented Programming using C++ Code:20CST151 Unit-3
  • 2. Object Oriented Programming using C++ Course Objectives 2 • To enable the students to understand various stages and constructs of C++ programming language and relate them to engineering programming problems. • To improve their ability to analyze and address variety of problems in programming domains.
  • 3. 3 CO Number Title Level CO1 Provide the environment that allows students to understand object-oriented programming Concepts. Understand CO2 Demonstrate basic experimental skills for differentiating between object-oriented and procedural programming paradigms and the advantages of object-oriented programs. Remember CO3 Demonstrate their coding skill on complex programming concepts and use it for generating solutions for engineering and mathematical problems. Understand CO4 Develop skills to understand the application of classes, objects, constructors, destructors, inheritance, operator overloading and polymorphism, pointers, virtual functions, exception handling, file operations and handling. Understand Course Outcomes
  • 4. Scheme of Evaluation 4 Sr. No. Type of Assessment Task Weightage of actual conduct Frequency of Task Final Weightage in Internal Assessment (Prorated Marks) Remarks 1. Assignment* 10 marks of each assignment One Per Unit 10 marks As applicable to course types depicted above. 2. Time Bound Surprise Test 12 marks for each test One per Unit 4 marks As applicable to course types depicted above. 3. Quiz 4 marks of each quiz 2 per Unit 4marks As applicable to course types depicted above. 4. Mid-Semester Test** 20 marks for one MST. 2 per semester 20 marks As applicable to course types depicted above. 5. Presentation*** Non Graded: Engagement Task Only for Self Study MNGCourses. 6. Homework NA One per lecture topic (of 2 questions) Non-Graded: Engagement Task As applicable to course types depicted above. 7. Discussion Forum NA One per Chapter Non Graded: Engagement Task As applicable to course types depicted above. 8. Attendance and Engagement Score on BB NA NA 2 marks
  • 5. Why When amount of memory to be allocated is not known beforehand, rather it is determined at the time of program run, it is called Dynamic Memory Allocation. It leads to efficient utilization of storage space. What Dynamic memory allocation means creating memory at runtime. It can be done with the help of new operator in CPP.
  • 6. • Introduction to DMA • Static Memory Allocation and Dynamic Memory Allocation • New and delete operator 6 CONTENTS
  • 7. Static Memory Allocation Static memory allocation happens for Static and global variables. Memory for these types of variables is allocated once when your program is run and persists throughout the life of your program. When amount of memory to be allocated is known beforehand i.e. at the time of compilation, it is known as Static Memory Allocation. Once the memory is allocated statically, it cannot be de-allocated during program run. So it leads to wastage of storage space. The Stack is used for static memory allocation. Example: int A[100]; 7
  • 8. Dynamic memory allocation When you dynamically allocate memory, you are asking the operating system to reserve some of that memory for your program’s use. When your application is done with the memory, it can return the memory back to the operating system to be given to another program. Unlike static, the program itself is responsible for requesting and disposing of dynamically allocated memory. In CPP this can be done with the help of new and delete operator. The Heap is used for Dynamic memory allocation. 8
  • 9. Dynamic memory allocation When amount of memory to be allocated is not known beforehand, rather it is determined at the time of program run, it is called Dynamic Memory Allocation. It leads to efficient utilization of storage space. Example: cout << " Enter number of elements: "; cin >> N; int *A = new int[N]; // dynamic memory allocation 9
  • 10. C++ new operator Dynamic memory allocation means creating memory at runtime. For example, when we declare an array, we must provide size of array in our source code to allocate memory at compile time. But if we need to allocate memory at runtime must use new operator followed by data type. If we need to allocate memory for more than one element, we must provide total number of elements required in square bracket[ ]. It will return the address of first byte of memory 10
  • 11. 11 ptr = new data-type; //allocate memory for one element ptr = new data-type [ size ]; //allocate memory for fixed number of element Syntax of new operator
  • 12. 12 Delete operator is used to deallocate the memory created by new operator at run-time. Once the memory is no longer needed it should by freed so that the memory becomes available again for other request of dynamic memory. Syntax of delete operator delete ptr; //deallocate memory for one element delete[] ptr; //deallocate memory for array C++ Delete operator
  • 13. Example of c++ new and delete operator #include<iostream.h> #include<conio.h> void main() { int size,i; int *ptr; cout<<"ntEnter size of Array : "; cin>>size; 13
  • 14. 14 ptr = new int[size]; //Creating memory at run-time and return first byte of address to ptr. for(i=0;i<5;i++) //Input array from user. { cout<<"nEnter any number : "; cin>>ptr[i]; } for(i=0;i<5;i++) //Output arrray to console. cout<<ptr[i]<<", "; Example of c++ new and delete operator
  • 15. Example of c++ new and delete operator delete[] ptr; //deallocating all the memory created by new operator } Output : Enter size of Array : 5 Enter any number : 78 Enter any number : 45 Enter any number : 12 Enter any number : 89 Enter any number : 56 78, 45, 12, 89, 56, 15
  • 16. Use of new and delete operator in class #include <iostream> using namespace std; class Box { public: Box() { cout << "Constructor called!" <<endl; } ~Box() { cout << "Destructor called!" <<endl; } }; int main() { Box* myBoxArray = new Box[4]; 16
  • 17. Use of new and delete operator in class delete [] myBoxArray; // Delete array return 0; } Output is: Constructor called! Constructor called! Constructor called! Constructor called! Destructor called! Destructor called! Destructor called! Destructor called! 17
  • 18. Applications of DMA • Dynamically Allocated Memory is used to allocate memory of variable size which is not possible with compiler allocated memory except variable length arrays. • Most important use of DMA is flexibility provided to programmers. We are free to allocate and de-allocate memory whenever we need and whenever we don’t need anymore. There are many cases where this flexibility helps. Examples of such cases are linked list ,tree etc. 18
  • 19. 19 Summary In this lecture we have discussed about DMA. We have discussed about Static and Dynamic memory allocation. Discussed about new and delete operator. Discussed about new and delete operator in class.
  • 20. Frequently Asked question Q1 What is DMA? When amount of memory to be allocated is not known beforehand, rather it is determined at the time of program run, it is called Dynamic Memory Allocation. It leads to efficient utilization of storage space. Q2 What is static memory allocation? When amount of memory to be allocated is known beforehand i.e. at the the time of compilation, it is known as Static Memory Allocation. Once the memory is allocated statically, it cannot be deallocated during program run. So it leads to wastage of storage space. 20
  • 21. Q3 What is new operator? New operator is used to allocate memory at runtime .Syntax of new operator is: ptr = new data-type; //allocate memory for one element ptr = new data-type [ size ]; //allocate memory for fixed number of element Q4 What is delete operator? Delete operator is used to deallocate the memory created by new operator at run-time.Syntax of delete operator is delete ptr; //deallocate memory for one element delete[] ptr; //deallocate memory for array 21
  • 22. Assessment Questions: 22 1. Which of the following is not a false statement about new operator? a. It can’t be overloaded. b. It returns garbage value when memory allocation fails. c. It automatically computes the size of the data object. d. All of these 2.Which of the following is/are valid ways to allocate memory for an integer by dynamic memory allocation in CPP. a. int *p = new int(100); b. int *p; p = new int; *p = 100; c. int *p = NULL; p = new int; *p=100; d. Only 1,2 e. All of these
  • 23. Discussion forum. How can we differ Static memory Allocation and Dynamic Memory Allocation How to use new and delete operator ?? 23 https://youtu.be/UY2_lLpDu7U https://youtu.be/sRBB_qX4lKY
  • 24. REFERENCES Reference Books [1] Programming in C++ by Reema Thareja. [2] Programming in ANSI C++ by E. Balaguruswamy, Tata McGraw Hill. [3] Programming with C++ (Schaum's Outline Series) by Byron Gottfried Jitender Chhabra, Tata McGraw Hill. Websites: • https://www.geeksforgeeks.org/new-and-delete-operators-in- cpp-for-dynamic- • https://www.studytonight.com/cpp/memory-management-in- cpp.php YouTube Links: • https://youtu.be/UY2_lLpDu7U • https://youtu.be/sRBB_qX4lKY 24

Editor's Notes

  1. Computer in the diagram is 3rd generation computer. The period of third generation was from 1965-1971. The computers of third generation used Integrated Circuits (ICs) in place of transistors. A single IC has many transistors, resistors, and capacitors along with the associated circuitry. The main features of third generation are − IC used More reliable in comparison to previous two generations Smaller size Generated less heat Faster Lesser maintenance Costly AC required Consumed lesser electricity Supported high-level language