How do you deal with scoped allocations?

Namespace rswhite4 at googlemail.com
Sun Dec 8 11:00:28 PST 2013


> I just use
>     scope(exit) delete buf;
>
> Your solution seems to do a GC every time some buffer goes out 
> of scope, which is slooow.

I don't need scoped allocations that often. Otherwise I wouldn't 
use GC.minimize ;) or wouldn't use the GC at all.


John Colvin:
  > Well, for a start you're calling GC.minimize every time you 
leave
  > the scope, which is an expensive call.
That was my own decision and is of course not required, but I 
like to clean up the wasted space. [1]
And as I said, I don't use scope allocations that often.

  > Just using new and GC.free would be fine, but there is really 
no
  > need to burden the GC with this at all; it's a textbook case 
for
  > C's malloc/free.
The GC relies also on malloc / free.

Dmitry Olshansky:
  > There is no such objective quality as being D'ish.
  > GC.malloc/GC.free are no better then malloc/free in code style,
  > readability or observable effect.
But I don't use  GC.malloc / GC.free. I use new which is IMO a 
lot nicer and more clean. Of course I now that new is only D 
syntax for malloc but it is still more clean.

  > D offers you C run-time as well. In fact it builds on top of 
it.
  > See also (hopefully) soon to be formally reviewed 
std.allocator.
It is still C even if D offers the access to the C standard lib.

  > 1. Because GC.minimize does a hell of a work to optimize the 
whole GC
  > heap. For starters it does collection so as to get rid of 
floating
  > garbage (AFAIK).
  See [1]


More information about the Digitalmars-d mailing list