[Issue 14421] Variadic args array force on heap
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Apr 12 03:12:36 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14421
--- Comment #5 from yebblies <yebblies at gmail.com> ---
(In reply to John Colvin from comment #4)
> (In reply to yebblies from comment #3)
> > Is there a reason you can't overload and forward the variadic version to the
> > non-variadic after calling dup?
>
> I don't understand how that would help.
>
> What I'm concerned about is if making the variadic array argument creates a
> GC allocation, then the .dup makes another one.
If you have this:
char[] foo(char[] args...)
{
return foo(args.dup);
}
char[] foo(char[] args)
{
return args;
}
void main()
{
foo('a', 'b', 'c'); // this will call first overload, and dup
foo(['a', 'b', 'c']); // this will call second, no dup
}
The array will only be copied if the variadic version is called.
--
More information about the Digitalmars-d-bugs
mailing list