Share a Heap
To correctly share a heap, you must observe
certain requirements (none of these are done by default).
For a fixed-size shared heap, you must do the
following:
- Allocate the starting block of memory as
shared memory.
- Ensure that all processes that use the
heap (allocate or free memory from it) or that use shared
data from the heap (interested processes) have access to
the starting block.
- Pass the heap handle to each process that
uses the heap ("interested" processes do not
need the heap handle).
- Call _uopen for the heap in each process that uses it.
- Call _uclose in each process where you called _uopen before
you destroy the heap.
If you use _uaddmem to expand your heap, you must also ensure that all
interested and using processes have access to the new block.
If you use your own getmore_fn
and release_fn functions to dynamically expand and shrink your heap,
you must also do the following:
- Ensure that all interested and using
processes have access to the new block added by your getmore_fn function, no matter which process called getmore_fn.
- Ensure that your getmore_fn function can run successfully in any process
that may call a heap-specific allocation function (such
as _umalloc) or cause it
to be called.
- Ensure that your release_fn function can run successfully in any process
that may call _uheapmin or _udestroy or cause them to be called. Typically this
would mean placing both your getmore_fn and the release_fn functions in a DLL that is loaded by all
processes that use the heap handle. Any data these
functions use must also be shared.
- Ensure that your release_fn function revokes the access of each process to
a shared memory block before it returns that block to the
system.

Memory
Management Functions

Create Your Own Function to
Expand a Heap