APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed


© October 2003 Tony Lawrence

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.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> heap

Inexpensive and informative Apple related e-books:

Take Control of Parallels Desktop 12

Take Control of Automating Your Mac

Take Control of Pages

iOS 8: A Take Control Crash Course

Take Control of Upgrading to El Capitan

More Articles by © Tony Lawrence

Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

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)

Linux posts

Troubleshooting posts

This post tagged:



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode