Groups > Symbian > Symbian general discussion > Re: Can I dynamically change a thread's default heap?




Can I dynamically change a thread's default heap?

Can I dynamically change a thread's default heap?
Thu, 23 Nov 2006 17:13:33 +000
Hi.

I've created a chunk and am using UserHeap::ChunkHeap() to get a RHeap 
which I am then using for memory allocations within my application.

However, I am also calling a library which is making memory allocations 
and I want that library to allocate from the heap I have created. I have 
no control over the API or implementation of the library. The library 
will be making allocations from the default heap - one thought on how to 
override this is to set my own heap up as the default heap.

Does anyone know if this is possible (and if so, how)? Does anyone have 
any alternative suggestions?

Post Reply
Re: Can I dynamically change a thread's default heap?
Thu, 23 Nov 2006 17:48:40 +000
Ken wrote:
> [snip]  one thought on how to
> override this is to set my own heap up as the default heap.
> 
> Does anyone know if this is possible (and if so, how)? Does anyone have 
> any alternative suggestions?

OK, I found User::SwitchHeap() which seems to cause the right thing to 
happen - but I'm now getting a crash later on. Might there be something 
special I have to do (eg., what happens if something allocated using the 
original heap is freed while the new heap is current - is that free 
request sent to the heap that it was allocated from or the current heap) ?

Post Reply
Re: Can I dynamically change a thread's default heap?
Thu, 23 Nov 2006 18:51:12 -000
On Thu, 23 Nov 2006 17:48:40 -0000, Ken <nobody@nowhere.non> wrote:

> Ken wrote:
>> [snip]  one thought on how to
>> override this is to set my own heap up as the default heap.
>>  Does anyone know if this is possible (and if so, how)? Does anyone  
>> have any alternative suggestions?
>
> OK, I found User::SwitchHeap() which seems to cause the right thing to  
> happen - but I'm now getting a crash later on. Might there be something  
> special I have to do (eg., what happens if something allocated using the  
> original heap is freed while the new heap is current - is that free  
> request sent to the heap that it was allocated from or the current heap)  
> ?
>
> Thanks, Ken.

The current heap.

If you do this you do need to be very carefull about which heap you have  
active when. This is especially true when something leaves - you need to  
ensure that you switch the heap back.



-- 
Alan Montgomery

  /"\
  \ / ASCII ribbon campaign
   X  against HTML mail
Post Reply
about | contact