×
Namespaces

Variants
Actions

从缺省堆中分配内存单元

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
huwell 在 30 Jun 2007 创建
最后由 hamishwillee 在 15 Dec 2011 编辑
  • 设备, 软件 版本:

S60 3rd Edition


  • 描述:

一般来说内存单元是从当前线程堆中分配的,但有时无法这样做,特别当要分配的内存单元很大时。 我们可以生成一个新的堆,从它那里获取我们需要的内存单元,示例如下:

//Try to create a heap in a local chunk. 
//The minimum length of the heap is 10M and the maximum length is 20M
 
RHeap *pChunkHeap = UserHeap::ChunkHeap(NULL, 10000*1024, 20000*1024);
 
if (RHeap)
{
 
void *mallocBuffer = NULL;
 
TInt size = 8000*1024; //Try to allocate a 8M memory cell
 
mallocBuffer = pChunkHeap->Alloc(size);
 
if (mallocBuffer )
{
//... Use this memory cell ...
}
 
}
This page was last modified on 15 December 2011, at 13:08.
22 page views in the last 30 days.