### Create Your Own Function to Shrink a User-Defined Heap

To coalesce a user-defined heap (return all blocks in the heap that are totally free to the system), use _uheapmin. _uheapmin works like _heapmin, except that you specify the heap to use.

When you call _uheapmin to coalesce a heap or _udestroy to destroy it, these functions call your release_fn function to return the memory to the system. Again, it is up to you how you implement this function. You are also responsible for returning the initial block of memory that you supplied to _ucreate.

Your release_fn function must have the following prototype:

    void (*release_fn)(Heap_t uh, void *block, size_t size);

uh identifies the heap to be shrunk.

The pointer block and its size are passed to your function by _uheapmin or _udestroy. Your function must return the memory pointed to by block to the system. For example:

    static void release_fn(Heap_t uh, void *block, size_t size)
    {
    DosFreeMeme(block);
    return;
    }

    static void release_fn(Heap_t uh, void *block, size_t size)
    {
    VirtualFree(block,0,MEM-RELEASE);
    return;
    }

Because a fixed-size heap has no release_fn function, _uheapmin and _udestroy work slightly differently. Calling _uheapmin for a fixed-size heap has no effect but does not cause an error; _uheapmin simply returns 0. Calling _udestroy for a fixed-size heap marks the heap as destroyed, so no further operations can be performed on it, but it returns no memory. It is up to you to return the heap's memory to the system.

Memory Management Functions
Manage Memory with Multiple Heaps

Create Your Own Function to Expand a Heap
Use a User-Defined Heap