implicit-context v0.0.1

Guillaume Piolat first.name at gmail.com
Fri Sep 29 11:00:05 UTC 2023


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.



More information about the Digitalmars-d-announce mailing list