DIP 1008 Preliminary Review Round 1

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Mon May 22 07:08:00 PDT 2017


On Saturday, 20 May 2017 at 09:35:34 UTC, Stanislav Blinov wrote:
> On Saturday, 20 May 2017 at 02:25:45 UTC, Walter Bright wrote:
>>   void foo(scope string s);
>
> string s = callCAPIAndAllocateString();
> foo(s ~ "abc");
>
> What will happen? The compiler will generate different code? 
> Won't compile? The former means invisible performance gap. The 
> latter means an unpleasant surprise. Neither are good. Do we 
> really need such special cases?

It's no different from when s is GC allocated, s[] has to be 
copied for the concatenation. I'm not sure how Walter wants to 
lower this, but maybe it could use a region/stacked allocator. 
That could mean allocation in constant time when the region is 
already big enough, and deallocation would be constant time 
(except if freeing an unused region ahead of the current region).


More information about the Digitalmars-d mailing list