<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">2016-06-10 1:20 GMT+02:00 maik klein via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">But that means that the closure will be allocated on the stack right? What happens when I send it with <a href="http://dpldocs.info/experimental-docs/std.concurrency.send.html" rel="noreferrer" target="_blank">http://dpldocs.info/experimental-docs/std.concurrency.send.html</a><br>
<br>
Will it copy the function or will it only send the pointer?<br></blockquote><div><br>Yes it will be stack allocated.<br>But if you wish to `send` something, I think you're better off using a function in an object (disclaimer: never tried).<br>Functions are not copied, so I guess you are refering to the context pointer ?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
Also scope on local vars is marked to be deprecated, see <a href="http://stackoverflow.com/a/4713064/944430" rel="noreferrer" target="_blank">http://stackoverflow.com/a/4713064/944430</a><br>
<br></blockquote><div><br>Yeah and they are not going away anytime soon. There's a reason why the compiler won't even warn about them. They are extremely useful and there is currently no replacement for them.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
I don't think that I can use delegates (without the gc), what I basically do is send a delegate to a thread, create a fiber on that thread and put it in a thread local array.<br></blockquote><div><br>Did you try to send a native delegate ? I would be very surprised if you were allowed to do so.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
The delegate contains a "future" that I can access on a different thread. I use it as mechanism to share results. (Its synchronized with atomics)<br>
<br>
I mean currently I just use gc delegates, but I am exploring some alternatives.<br><br></blockquote><div> <br>Note that not all delegates allocate. Function local delegate refering to variable do, but the one refering to aggregate never do.<br><br>E.g. the following compiles and run:<br><br>```<br><div>struct Foobar { string toString() @nogc { return "Foobar"; } }</div><div><br></div><div>void func (string delegate() ts) @nogc {}</div><div>void main () @nogc</div><div>{</div><div>    scope c = new Object;</div><div>    Foobar s;</div><div>    func(&c.toString); // ptr=c funcptr=toString</div><div>    func(&s.toString); //ptr =s funcptr=toString</div><div><br></div><div>    string delegate() @nogc dg;</div><div>    dg.funcptr = (&s.toString).funcptr; // There might be a better way to do that</div><div>    dg.ptr  = &s;</div><div>    assert("Foobar" == dg());</div><div>}</div><div>```<br><br></div></div></div></div></div>