1. About.com
  2. Computing & Technology
  3. C / C++ / C#

Discuss in my forum

Definition of Heap

By , About.com Guide

Filed In:
  1. C / C++ / C#
Definition: The heap is the name for a block of RAM that is used to store dynamic variables, that is variables created by new (in C, C++ and C#). The application requests the memory and when it is finished with it, the memory can be released. (In C# this is done automatically without explicitly freeing it).

Heaps can suffer from fragmentation if lots of different size memory blocks are requested then freed up and so on. It's usual when a block is freed to add it to a list- called a free list. Future requests for heap memory are first checked against the free list and used instead of allocating it out of the main heap memory. But if a reused block is smaller than the block in the free list then that block is split in two, with a smaller block left in the free list. This fragmentation can eventually lead to applications running out of memory.

One way round this is to use Garbage Collection. The .NET framework has this built in, but developers using C or C++ have to write their own garbage collector or use a 3rd party memory manager.

Glossary:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Examples:
Don't confuse a heap with the stack

©2012 About.com. All rights reserved. 

A part of The New York Times Company.