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.<br>
<br><div class="gmail_quote">On Mon, Jul 18, 2011 at 11:10 AM, Steve Schveighoffer <span dir="ltr"><<a href="mailto:schveiguy@yahoo.com">schveiguy@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
>________________________________<br>
>From: David Simcha <<a href="mailto:dsimcha@gmail.com">dsimcha@gmail.com</a>><br>
<div class="im">><br>
>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:<br>
><br>
>RegionAllocator fun() {<br>
> RegionAllocator alloc;<br>
> alloc.malloc(42);<br>
><br>
> RegionAllocator alloc2;<br>
> alloc2.malloc(42);<br>
> return alloc2;<br>
>}<br>
><br>
>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.<br>
<br>
</div>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.<br>
<br>
-Steve<br>
<br>
_______________________________________________<br>
phobos mailing list<br>
<a href="mailto:phobos@puremagic.com">phobos@puremagic.com</a><br>
<a href="http://lists.puremagic.com/mailman/listinfo/phobos" target="_blank">http://lists.puremagic.com/mailman/listinfo/phobos</a><br>
</blockquote></div><br>