Memory Management: Using Heap

Scope rules and the variety of storage classes in C++ go a long way toward helping programmers to manage memory for program objects. However, these tools do not solve the problem of implementing dynamic data structures adequately.

Array implementations of dynamic data structures with a sentinel or a count of valid entries are powerful and simple. When the number of elements in the data set grows or shrinks, these implementations can add or remove components. Yet they need the maximum size of the data set known at compile time. Any choice of the maximum size might entail either a danger of overflow or wasted space.

Dynamic memory management resolves this problem by allocating and reallocating memory dynamically. ...

Get Core C++ A Software Engineering Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.