Idea for avoiding GC for lambdas

Steven Schveighoffer schveiguy at gmail.com
Wed Jun 23 13:41:42 UTC 2021


On 6/22/21 5:31 PM, H. S. Teoh wrote:
> On Tue, Jun 22, 2021 at 03:56:03PM -0400, Steven Schveighoffer via Digitalmars-d wrote:
> [...]
>> This again, is a misunderstanding of my proposal. I'm not talking
>> about altering delegates in any way.
>>
>> There are no delegates involved in `filter`. It is, instead, an inner
>> struct with a hidden context pointer. Could just as well be a struct
>> with context carried with it instead of allocated on the heap.
> [...]

[snip]

> Am I right?

Yes, exactly! The only tricky part is that the filter function has to 
explicitly accept the context so it can tell the compiler where to put 
the context.

Essentially, it gives a place to accept the context and has the compiler 
give it a way to forward that context to the lambda function(s).

It may be trickier than I originally wrote, but the goal is to avoid 
having to do any work as a user (the library can be instrumented as much 
as we want), and the compiler just does the right thing.

-Steve


More information about the Digitalmars-d mailing list