Reallocating a previously freed raw memory block

Sometimes it's useful to keep pointers to raw memory blocks that have been allocated on a heap and subsequently freed, in case they are needed again. Once a block has been freed, there is no guarantee that it can be reallocated, but if the memory it used has not been reused, it may be possible. To attempt to reallocate a block when its heap is known, use the heap's Reallocate() member function. For example, suppose you want to reallocate a block pointed to by blockPtr on localHeap, a heap of type TLocalMemoryHeap:

    localHeap.Reallocate(blockPtr, size);
To attempt to reallocate this block when its heap is not known, use ReallocateAny(), a static member function of TMemoryHeap:

    TMemoryHeap::ReallocateAny(blockPtr, size);
Both Reallocate() and ReallocateAny() use the size argument to resize the specified block.


[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