Each thread has a chunk which contains that thread's program stack. For the main thread of a process, this chunk also contains the thread's heap. A program's request for memory is allocated from this heap. For example, a code fragment such as:
CArrayFixFlat<...>* fixflat;
...
fixflat = new (ELeave) CArrayFixFlat<...>(3);
causes a portion of memory to be allocated from the heap and its address returned to the caller. Memory from the heap must be explicitly requested and, importantly, explicitly freed by the program.
If a process creates additional threads, then a new chunk is created for each new thread. Each chunk contains the thread's stack; if a new thread is not sharing an existing heap, then the chunk also contains a new heap.
When a new thread is created, either:
a new heap is created for it
it uses the creating thread's heap
it uses an explicitly referenced heap.
A thread gets the handle to its heap by calling
User::Heap()
.