How to switch heaps

After a call to User::SwitchHeap() , any new request for memory is satisfied from the new heap.

A thread can switch between heaps using User::SwitchHeap() .

After a call to this function, any new request for memory is satisfied from the new heap.

When freeing memory, it is extremely important that the current heap is the heap from which it was allocated. Trying to free a memory cell from a heap when it was allocated from a different heap has undefined consequences.

      
       
      
      Thing* mything = new Thing;                // Allocate on current heap
RHeap* oldHeap = User::SwitchHeap(newHeap);// Change heaps
...                                        // Use new heap
User::SwitchHeap(oldHeap);                 // Change to old heap
delete mything;                            // before deleting.