Looks good.

Maybe nesting is a good name for the whole concept.
This would require further introductory explanation at the module header.
Possibly this can be partly merge with the explanation of stack pointer bumping.

/*
 * ...
* Multiple instances of RegionAllocator may use the same stack in which case
 * they are nested instances.
 * When a nested RegionAllocator is destroyed, all memory allocated by it
 * is returned to its stack.
 * Memory may only be allocated by the most nested RegionAllocator.
 */

/*
 * Creates a RegionAllocator using a thread local stack.
 * If the thread local stack is already used by a RegionAllocator
 * the returned RegionAllocator will be nested.
 */
newRegionAllocator();

/*
 * Creates a RegionAllocator using a new stack.
 * The stack will be freed when the returned RegionAllocator is destroyed.
 */
newRegionAllocator(size_t segmentSize, GCScan scan = GCScan.no);

struct RegionAllocator
{
    /*
     * Returns a new RegionAllocator using the same stack as this instance.
     * When the nested allocator is destroyed all memory allocated by
     * it will be freed. Memory allocated by this instance is unaffected.
     * You may only allocate memory using the most nested instance.
     */
    RegionAllocator nestedAllocator();
}

Reply via email to