Free Store and Heap

Question:
Is there any difference between heap and free store in C++?

Answer:
The free store is a region of memory from which a program allocates dynamic memory using new. In most cases, the free store is implemented as a heap. Therefore, each allocation request returns a memory address that is higher than the previous one (as opposed to a stack, for instance). The terms “free store” and “heap” are often used interchangeably in the literature although technically, the free store needn’t be implemented as a heap. Note also that “free store” is only applicable to C++. In C, the region of dynamic memory available at runtime is called “the heap” and is allocated using malloc() or calloc(). Note that malloc() and new might access two different memory heaps. Therefore, you shouln’t relase memory allocated using malloc() with delete or call free() to release memory allocated using new.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: