You are on page 1of 12

MASIRA

REPRESENTING
SHAIKH
SYBBA(CA)
ROLL NO-69
TOPIC: HOW MEMORY MANAGED IN
C++
WHAT IS MEMORY MANGEMENMENT IN C+
+?
Memory management in C++ is a technique of managing the
computer memory and assigning required memory space to the
programs for execution.
It is almost relatable and is based on the same concept as other
Programming languages.
It deals with the space and memory assignment in terms of
improvisation for the entire computer system and its performance.

Presentation title 3
HOW DOES MEMORY MANAGEMENT WORK
IN C++?
Memory management is one of the pivotal and important concepts for
any programming language so is the case with C++.
Concept outline of Memory management primarily revolves around
the time-space trade-off and memory allocation concept.
It helps in managing the space and memory-related issues with the
help of arrays.
Arrays are the data structure that is the main component or can be
said that aids memory management concept. How to let’s check the
flow.

Presentation title 4
Memory in the C++ program is divided into two parts:

•Stack: All variables declared inside any function take up the stack's
memory.

•Heap: It is the unused memory of the program and can be used to


allocate the memory at runtime dynamically.

Presentation title 5
MEMORY MANAGEMENT OPERATOR IN C++

1.New Operator :

A new operator is used for creating the object which exists and
remains in active mode which means the allocation of memory will still
be active.
This remains in active state i.e. the existence of a new object is there
until the delete() operator is called which will be discussed in the next
section.

Presentation title 6
The syntax flow for the new operator with respect to the
memory management allocation is as follows:
ptr_var = new data_tp

• ptr_var: This represents the name of the pointer variable.


• new: operator for the creation of the object for allocation.
• data_tp: represents the type of data used while allocation.

Presentation title 7
2.Delete Operator:

On the other hand, Delete Operator is also a unary operator used for
memory management and comes into the picture only when the new
operator is used for memory allocation which signifies another fact
that the delete operator is fully dependent on the new operator.

Presentation title 8
Once the new operator finishes its work of allocation and tries to free
its memory or to remove the unused or excess memory allocated it will
immediately call for the Delete Operator.

Syntax:
Delete PointerVariable delete ptr;

Presentation title 9
Example: This program demonstrates the New Operator which is used for creation
of new object for object allocation and memory management as shown in the output.

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int no;
cout << "Total_Students_In_One_Batch";
cin >> no;
float* pon_tr;
pon_tr = new float[no];

Presentation title 10
cout << "Marks_Of_Students" << endl;

for (int k = 0; k < no; ++k)


{
cout << "Student_mrk" << k + 1 << ": ";
cin >> *(pon_tr + k);
}

cout << "\nDisplay the Total marks of Students" << endl;


for (int k = 0; k < no; ++k)
{

cout << "Student_mrk" << k + 1 << " :" << *(pon_tr + k) << endl;
}
delete [] pon_tr;
return 0;
}

Presentation title 11
THANK YOU

You might also like