devxlogo

Advantages of automatic storage vs. heap storage

Advantages of automatic storage vs. heap storage

Using operator new (or malloc() in C) to create objects on the heap is expensive in terms of performance (allocating heap memory usually involves a long negotiation with the OS), maintenance (dynamic allocation may fail; extra code to handle such exception is required) and safety (object may be deleted more than once or not deleted at all) as demonstrated in the following example:

 void f() {string *p = new string(2000);  //initial size of 2000 chars						//...meddle with pif (condition) {	cout<<

See also  The Benefits of Patient Engagement Solutions for Healthcare Providers
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist