Trying to avoid the GC
ketmar via Digitalmars-d
digitalmars-d at puremagic.com
Wed Dec 31 13:48:30 PST 2014
On Wed, 31 Dec 2014 13:52:02 +0000
"Adam D. Ruppe via Digitalmars-d" <digitalmars-d at puremagic.com> wrote:
> On Wednesday, 31 December 2014 at 13:38:05 UTC, Shachar Shemesh
> wrote:
> > alias dtype = void delegate(int i);
> > void func(T)( T d )
>
>
> Try writing that:
>
> void func(scope dtype d)
>
> instead. Or (scope T d) should do it too if you need it to be
> templated. The scope keyword tells the compiler that you promise
> not to escape it from that scope, so it is safe to use stack
> memory. Should prevent the copying to gc of a delegate. (One of
> the few places the scope keyword is actually implemented to do
> something!)
an it's so well hidden that not many people know about it. being a not
very careful reader myself i discovered such `scope` usage while
reading some code in another project and was a little puzzled.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141231/a09ce0fc/attachment.sig>
More information about the Digitalmars-d
mailing list