implicit-context v0.0.1
Imperatorn
johan_forsberg_86 at hotmail.com
Fri Sep 29 15:00:33 UTC 2023
On Friday, 29 September 2023 at 11:00:05 UTC, Guillaume Piolat
wrote:
> On Friday, 29 September 2023 at 08:33:56 UTC, Imperatorn wrote:
>> Interesting, what are the benefits of using this instead of
>> global variables?
>
> Thinking about this, it's more vs TLS variable. __gshared would
> require synchronization.
>
> Changing the theAllocator (a TLS variable) in
> std.experimental.allocator looks like this:
>
>
> auto save = theAllocator;
> theAllocator = myAllocator;
>
> // do stuff with custom allocator
>
> theAllocator = save;
>
>
>
> Changing the allocator in implicit-context looks like this
>
>
> context.push;
> context.allocator = myAlloc;
>
> // do stuff with custom allocator
>
> context.pop;
>
>
> so now that I think about it I'm not sure if there is an
> substantial advantage over simply having TLS variables. I had
> the goal of allowing .alloca on that secondary stack. If there
> is many context variables, push and pop will be a bit faster to
> write than all the temporaries.
I understand, it's more like if you mix optional parameters and
dependency injection?
I think for this to be truly valuable, it would require being
part of the language.
I admit I haven't really thought about implicit parameters before
your post, so I might be missing something.
More information about the Digitalmars-d-announce
mailing list