digitalmars.D.learn - Is there anyway to make opApply nogc?
- Gary Willoughby (10/10) Jun 20 2016 Is there any way to make opApply @nogc? or provide the same
- Mathias Lang (3/13) Jun 20 2016 Can't `opApply` with `auto` return type works since it infers
- Gary Willoughby (3/5) Jun 20 2016 I think the problem is that the delegate which is required by
- Adam D. Ruppe (3/5) Jun 20 2016 make the delegate in opApply scope
- Gary Willoughby (2/7) Jun 20 2016 What effect does this have? and how does it beat the GC?
- Gary Willoughby (4/13) Jun 20 2016 Found the explanation here:
- Gary Willoughby (7/12) Jun 21 2016 I'm still not sure what this achieves. The description on the
- Adam D. Ruppe (6/8) Jun 21 2016 So when you use local variables in a delegate, the compiler
- Gary Willoughby (3/11) Jun 21 2016 Right ok, thanks! It doesn't seem to help though as the compiler
- Marc =?UTF-8?B?U2Now7x0eg==?= (4/6) Jun 22 2016 You probably need to declare the delegate and opApply() itself as
- Gary Willoughby (2/8) Jun 22 2016 That fixed it, thanks all for your help. :)
Is there any way to make opApply nogc? or provide the same foreach functionality without implementing a range interface? I want to iterate over a piece of memory using a pointer. I thought about using opSlice but that doesn't provide information for an index in a foreach loop. auto opSlice() { return this._pointer[0 .. size]; } Anyone got any ideas?
Jun 20 2016
On Monday, 20 June 2016 at 14:08:58 UTC, Gary Willoughby wrote:Is there any way to make opApply nogc? or provide the same foreach functionality without implementing a range interface? I want to iterate over a piece of memory using a pointer. I thought about using opSlice but that doesn't provide information for an index in a foreach loop. auto opSlice() { return this._pointer[0 .. size]; } Anyone got any ideas?Can't `opApply` with `auto` return type works since it infers attributes ?
Jun 20 2016
On Monday, 20 June 2016 at 14:34:33 UTC, Mathias Lang wrote:Can't `opApply` with `auto` return type works since it infers attributes ?I think the problem is that the delegate which is required by opApply is allocated using the GC.
Jun 20 2016
On Monday, 20 June 2016 at 15:13:53 UTC, Gary Willoughby wrote:I think the problem is that the delegate which is required by opApply is allocated using the GC.make the delegate in opApply scope int opApply(scope int delegate(whatever) dg)
Jun 20 2016
On Monday, 20 June 2016 at 15:27:32 UTC, Adam D. Ruppe wrote:On Monday, 20 June 2016 at 15:13:53 UTC, Gary Willoughby wrote:What effect does this have? and how does it beat the GC?I think the problem is that the delegate which is required by opApply is allocated using the GC.make the delegate in opApply scope int opApply(scope int delegate(whatever) dg)
Jun 20 2016
On Monday, 20 June 2016 at 15:47:44 UTC, Gary Willoughby wrote:On Monday, 20 June 2016 at 15:27:32 UTC, Adam D. Ruppe wrote:Found the explanation here: http://stackoverflow.com/questions/4711309/meaning-of-scope-in-d-for-a-parameter I give it a go. Thanks.On Monday, 20 June 2016 at 15:13:53 UTC, Gary Willoughby wrote:What effect does this have? and how does it beat the GC?I think the problem is that the delegate which is required by opApply is allocated using the GC.make the delegate in opApply scope int opApply(scope int delegate(whatever) dg)
Jun 20 2016
On Monday, 20 June 2016 at 15:27:32 UTC, Adam D. Ruppe wrote:On Monday, 20 June 2016 at 15:13:53 UTC, Gary Willoughby wrote:I'm still not sure what this achieves. The description on the stackoverflow question reads: "And when the compiler sees this on delegates, it will avoid allocating a closure when taking the address of a local function. This is essential in opApply loops." I have no idea what that means. Can anyone shed more light on this, please?I think the problem is that the delegate which is required by opApply is allocated using the GC.make the delegate in opApply scope int opApply(scope int delegate(whatever) dg)
Jun 21 2016
On Tuesday, 21 June 2016 at 12:48:04 UTC, Gary Willoughby wrote:I have no idea what that means. Can anyone shed more light on this, please?So when you use local variables in a delegate, the compiler usually makes a copy of them just in case the delegate gets saved for later. When you mark it scope, you promise that you won't save it for later, so the compiler skips making the copy.
Jun 21 2016
On Tuesday, 21 June 2016 at 12:53:11 UTC, Adam D. Ruppe wrote:On Tuesday, 21 June 2016 at 12:48:04 UTC, Gary Willoughby wrote:Right ok, thanks! It doesn't seem to help though as the compiler complains about it being not nogc.I have no idea what that means. Can anyone shed more light on this, please?So when you use local variables in a delegate, the compiler usually makes a copy of them just in case the delegate gets saved for later. When you mark it scope, you promise that you won't save it for later, so the compiler skips making the copy.
Jun 21 2016
On Tuesday, 21 June 2016 at 19:21:01 UTC, Gary Willoughby wrote:Right ok, thanks! It doesn't seem to help though as the compiler complains about it being not nogc.You probably need to declare the delegate and opApply() itself as nogc, too: int opApply(scope int delegate(int) nogc dg) nogc { }
Jun 22 2016
On Wednesday, 22 June 2016 at 13:36:54 UTC, Marc Schütz wrote:On Tuesday, 21 June 2016 at 19:21:01 UTC, Gary Willoughby wrote:That fixed it, thanks all for your help. :)Right ok, thanks! It doesn't seem to help though as the compiler complains about it being not nogc.You probably need to declare the delegate and opApply() itself as nogc, too: int opApply(scope int delegate(int) nogc dg) nogc { }
Jun 22 2016