The heap-memory tagline says:
The heap is process memory set aside for dynamic allocation.
Which seems vague enough to cover questions that have dynamic allocation in it, but the tag wiki gives a different story:
A heap memory pool is an internal memory pool created at start-up that tasks use to dynamically allocate memory as needed. This memory pool is used by tasks that requires a lot of memory from the stack, such as tasks that use wide columns.
For example, in Sybase's Adaptive Server Enterprise, if you make a wide column or row change, the temporary buffer this task uses can be as large as 16K, which is too big to allocate from the stack. Adaptive Server dynamically allocates and frees memory during the task’s runtime.
The heap memory pool dramatically reduces the predeclared stack size for each task, while also improving the efficiency of memory usage in the server. The heap memory the task uses is returned to the heap memory pool when the task is finished.
Microsoft describes a heap for their SQL Server 2008 R2 as a table without a clustered index. Heaps have one row in sys.partitions, with index_id = 0 for each partition used by the heap. By default, a heap has a single partition. When a heap has multiple partitions, each partition has a heap structure that contains the data for that specific partition. For example, if a heap has four partitions, there are four heap structures; one in each partition.
The C++ standard has references to "dynamic allocation" and "dynamic storage duration", but AFAIK has no notion of the "heap" or "stack", which are operating system specifics. For example, here's a conversation dealing with this misconception:
temporary objectexist in the stack? or heap?
remyabel: @pezy That's an operating system detail.
pezy: @remyabel some guys say: use
newwould put in heap, otherwise in stack? Is it right?
MSalters: @pezy: The short answer is no, the long answer would start with "perhaps..." but not fit in a comment. As remyabel points out, the OS is really in charge and C++ just tells you how long the object lives, not where. ( "heap" => "until delete", "stack" => "until function returns", "global" => until program exits, "temporary" => until end of statement)
In those languages, allocation involves the use of a few different techniques: