Passing array as const slows down code?

Era Scarecrow rtcvb32 at yahoo.com
Fri Apr 27 16:26:38 PDT 2012


On Friday, 27 April 2012 at 22:40:46 UTC, H. S. Teoh wrote:
> I recommend the opposite, actually. Most D code by default 
> should be @safe (don't know about nothrow though). It's good to 
> mark most things as @safe and pure, and let the compiler catch 
> careless mistakes.

  Your probably right..

> Dynamic arrays are always passed by reference (i.e. fat 
> pointer). AFAIK
> the compiler does not change this just because of certain tags 
> on the function.

  That's why i wasn't sure... I was pretty sure it was passed via 
fat pointer but if adding @safe and pure makes it slower, 
something else is going on. Perhaps just a ton more checks to 
make sure it doesn't during debug mode?

> No, that's wrong. The compiler checks the code at runtime to 
> prevent
> impure code from slipping into the binary. It does not do 
> anything to
> "patch over" impure code to make it pure.

  I'm not going to argue, I don't know enough about the D compiler 
to know exactly what's going on; Plus I'd rather be wrong than 
right :)

  I guess use a profiler and check where your bottlenecks are. The 
results may surprise you. I've only glanced over the code so I 
can't offer anything more concrete.


More information about the Digitalmars-d-learn mailing list