Ok, implemented. It definitely makes the design cleaner. Thanks again.
The delay was just because I had waited a while to see if any other
comments came up that would make me change my mind or turn the whole
design upside down.
Code:
https://github.com/dsimcha/TempAlloc/tree/master/std/allocators
Docs:
http://cis.jhu.edu/~dsimcha/d/phobos/std_allocators_allocator.html
http://cis.jhu.edu/~dsimcha/d/phobos/std_allocators_gc.html
http://cis.jhu.edu/~dsimcha/d/phobos/std_allocators_region.html
On 9/11/2011 7:28 PM, Martin Nowak wrote:
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();
}