|
Symbian sdk帮助-Heaps 译文作者: Leefj
|
| 译文版本:1.0 译文时间:2005-12-9 |
|
| |
|
|
|
Heaps
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:
每一个线程都有一个包含了自身程序栈(program stack)的chunk。对于进程的主线程来说,这个chunk中同样也包含了线程heap。程序对于内存的请求都是从这个heap的地址空间来分配的,例如有以下代码:
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.
程序请求了heap中部分的内存地址,并把地址返回给调用者。请求heap中的内存必须是显式的,同样,释放这些内存时也必须进行显式调用。
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.
如果进程创建了另外的线程,那么每个新线程都被创建一个新的chunk。每个chunk都包括了线程栈;如果新的线程没有共享到一个已经存在的heap(堆),那么chunk同样包含了一个新的heap。
When a new thread is created, either:
当一个线程被创建,以下情况的一个将会出现
a new heap is created for it ,it uses the creating thread's heap
创建一个heap,线程使用这个新建的heap。
it uses an explicitly referenced heap.
线程使用一个显式引用的heap。
A thread gets the handle to its heap by calling User::Heap().
线程使用User::Heap()获得它的heap的句柄。
|