c++ - Memory of a variable or object automatically terminated of finish at the end of program than why we use destructor? -
c++ - Memory of a variable or object automatically terminated of finish at the end of program than why we use destructor? -
in next programme creating circle object in local scope because not using new keyword. know memory of variable or object automatically terminated of finish @ end of programme why utilize destruct?
#include<iostream> using namespace std; class circle //specify class { private : double radius; //class info members public: circle() //default constructor { radius = 0; } void setradius(double r) //function set info { radius = r; } double getarea() { homecoming 3.14 * radius * radius; } ~circle() //destructor {} }; int main() { circle c; //defalut constructor invoked cout << c.getarea()<<endl; homecoming 0; }
assuming memory infinite resource dangerous. think real-time application needs run 24x7 , hear info feed @ high rate (let' 1,000 messages per second). each message around 1kb , each time allocates new memory block (in heap obviously) each message. altogether, need around 82 gb per day. if don't manage memory, can see happen. i'm not talking sophisticated memory pool techniques or alike. simple arithmetic calculation, can see can't store messages in memory. illustration have think memory management (from both allocation , deallocation perspectives).
c++ oop constructor destructor
Comments
Post a Comment