[phobos] Returning Scoped Allocators From Functions
David Simcha
dsimcha at gmail.com
Mon Jul 18 08:44:25 PDT 2011
I already solved it, actually, with an extra check on destroying a region.
If the last copy of an old RegionAllocator instance dies before the last
copy of a new RegionAllocator instance, an exception gets thrown on the
death of the RegionAllocator instance and subsequent d'tor call.
On Mon, Jul 18, 2011 at 11:10 AM, Steve Schveighoffer
<schveiguy at yahoo.com>wrote:
>
> >________________________________
> >From: David Simcha <dsimcha at gmail.com>
> >
> >I'm working on retrofitting TempAlloc (renamed to RegionAllocator)to fit
> Andrei's proposed allocator interface. One issue I've run into is, what
> happens when a scoped allocator is returned from a function? For example:
> >
> >RegionAllocator fun() {
> > RegionAllocator alloc;
> > alloc.malloc(42);
> >
> > RegionAllocator alloc2;
> > alloc2.malloc(42);
> > return alloc2;
> >}
> >
> >Now, alloc has died and alloc2 is still alive, violating LIFO
> requirements. Since it's virtually impossible to do by mistake, I'm
> inclined to just make returning a RegionAllocator from a function after
> another one has been subsequently created undefined behavior.
>
> Can RegionAllocator check on postblit (called during return? not sure) at
> least in debug mode whether it's valid or not. I think this might solve the
> problem.
>
> -Steve
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20110718/9302aeaf/attachment.html>
More information about the phobos
mailing list