1. Home
  2. Computing & Technology
  3. C / C++ / C#

Definition of Heap

By , About.com Guide

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
Explore C / C++ / C#
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

©2009 About.com, a part of The New York Times Company.

All rights reserved.