There are two general meanings for heap in the computer world. The first is unallocated memory available to your program. Low level languages have to specifically request allocation of memory for storage of non-stack variables. Higher level languages handle that behind the scenes, getting memory for you as and when needed. In either case, they get it from the heap. The system calls that do that are "calloc" and "malloc". Underneath, these used to call "brk" to actually get memory from the OS and "sbrk" to find out how much was currently available.
As modern OS level virtual memory systems are highly efficient and don't really give any physical memory up until it is written to, there is really no need for user programs to have to request memory: they can be just given whatever the largest possible address space is at startup. Modern man pages for "brk" reflect that, calling brk and sbrk " historical curiosities", and in fact there has even been talk of removing these entirely.
Garbage collection is the process of cleaning up memory once allocated but no longer needed. Interestingly, although the purpose and the general method of doing this are the same in both the operating system and any given high level language, the function would usually be referred to as "reclaiming memory" or "memory management" in the OS. This more respectful tone probably comes from the fact that some high level languages didn't do it all that well, and would lose track of memory (a "memory leak") or tie up your process for far too long doing the reclamation.
The second meaning of heap is a tree data structure, but those are more often just referred to as trees and what you are more likely to hear is B-Tree, which is just one possible type. Databases often use this type of indexing for fast lookups when hashing isn't possible.
The "heapsort" is a sorting technique that uses such a structure to accomplish the sort. You might hear someone arguing over wheether to use Heapsort or Quicksort; if so the issue at hand is probably the size of the dataset and the available memory: heapsort requires less legroom.
Got something to add? Send me email.
More Articles by Tony Lawrence © 2011-07-06 Tony Lawrence
The activity of "debugging", or removing bugs from a program, ends when people get tired of doing it, not when the bugs are removed. (Datamation)