Allocating on a non-default heap

To allocate an object, such as a TStandardText object, on a heap you have explicitly created, it's helpful to create a TAllocationHeap object to refer to the heap. You can then pass the TAllocationHeap object as an argument to a special new operator that allocates the new object on the specified heap:

      TAllocationHeap allocHeap(heap);        // heap is a subclass of TMemoryHeap
      
      TStandardText* textPtr = new(allocHeap) TStandardText("Some text");
Like the standard C++ new operator, this global overloaded new operator calls the object's constructor after it allocates the necessary heap space.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker