Closing and destroying a heap

When a process has finished using the heap, close it with _uclose. Once you have closed the heap in a process, that process can no longer allocate from or return memory to that heap. If other processes share the heap, they can still use it until you close it in each of them. Performing operations on a heap after you have closed it causes undefined behavior.

To destroy a heap, do the following:

After you destroy a heap, it is up to you to return the memory for the heap (the initial block of memory you supplied to _ucreate and any other blocks added by _uaddmem) to the system.

Writing the heap-shrinking function

When you call _uheapmin or _udestroy to coalesce or destroy a dynamically-sized heap, these functions call your heap-shrinking function to return the memory to the system. It is up to you how you implement this function.

Your function must have the following prototype:

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

Where functionName identifies the function (you can name it however you want), 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 shrinkHeap(Heap_t uh, void *block, size_t size)
{
  free(block);
  return;
}