Do a class invariants affect -release builds?
Chris Wright via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Dec 5 15:54:15 PST 2015
On Sat, 05 Dec 2015 23:06:22 +0000, Andrew LaChance wrote:
> I was reading a blog post here: http://3d.benjamin-thaut.de/?p=20 which
> mentions:
>
> "Calls to the druntime invariant handler are emitted in release build
> also and there is no way to turn them off. Even if the class does not
> have any invariants the invariant handler will always be called, walk
> the class hirarchy and generate multiple cache misses without actually
> doing anything."
>
> I was curious if this was still true today (the post was written 3 years
> ago in Sept 2012).
>
> Thanks!
It's not true today, as you can test yourself:
class Foo {
invariant {
assert(false);
}
string str() {
return this.toString;
}
}
void main() {
import std.stdio;
writeln(new Foo().str);
}
$ rdmd invar.d
core.exception.AssertError at invar.d(3): Assertion failure
$ rdmd -release invar.d
invar.Foo
I've never used a release build of anything. Bounds checking isn't that
expensive.
More information about the Digitalmars-d-learn
mailing list