Dconf 2015 talks...
Joseph Rushton Wakeling via Digitalmars-d
digitalmars-d at puremagic.com
Mon Feb 8 11:46:19 PST 2016
On Monday, 8 February 2016 at 00:54:24 UTC, Era Scarecrow wrote:
> Either they use more stack space, or they act normally after
> their call is done and are deallocated normally (automatically,
> unless they are passed outside of the scope where they were
> generated).
It's that "passed outside of the scope where they were generated"
that is bothering me.
Consider:
auto foo (Range) (Range r)
if (isInputRange!Range)
{
return r.randomSample(100).take(10);
}
void main ()
{
iota(1000).foo.writeln;
}
If the RandomSample internals are allocated on the stack using
the technique you propose, what's going to happen here?
> True; Perhaps have one RNG for seeding and one RNG for
> passing, then reseed after passing the function off, although
> how far deep some of this could go with it's deeper copying; I
> don't know.
No, I really don't think that's an approach that's worth
pursuing, except as a desperate workaround for the faults of the
existing design. RNGs should as much as possible "just work" and
the user shouldn't have to concern themselves like this with
> Perhaps RNG should be a class outright, which probably removes
> a lot of these problems.
It does indeed give you the desired reference semantics very
cheaply. But now suppose you have lots of RandomSamples being
instantiated in the inner loop of your program. If _they_ are
also a class, how do you handle their instantiation and
deallocation?
More information about the Digitalmars-d
mailing list