Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Oct 9, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

How Do 'New' and 'Delete' Actually Work?

The C++ runtime library includes a heap manager (subroutines responsible for maintaining the heap). The heap manager does bookkeeping to keep track of which parts of the heap have been loaned out for usage (allocated), and which parts are still free (deallocated).

Every time a call to 'new' is made, the heap manager does the following things:

(1) It searches the free part of the heap for a chunk of memory that is big enough.

(2) It makes a record of the fact that the chunk of memory is now allocated.

(3) It returns the starting address of the allocated chunk as a result.

When you call delete, the heap manager updates its records to note that the block is free.
Prashant Mhatre
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date