Paralysis of analysis
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Dec 14 11:30:04 PST 2010
On 12/14/10 1:19 PM, so wrote:
> Could you please elaborate the disadvantages part?
>
> Thanks!
Consider the empty() property. A struct using a pointer internally can
return true from empty if the pointer is null. A class cannot do that.
struct Array {
Impl * p;
@property bool empty() { return !p || p.empty; }
}
vs.
class Array {
@property final bool empty() { ... }
}
Whatever empty() does, it must be called against an already-allocated
reference to an Array.
The two words overhead comes from the vtable and the mutex.
A struct that has control over its own storage can be more aggressive
about releasing unused memory. A class does not have that kind of
control because it doesn't know how many references are out there to the
same object.
Andrei
More information about the Digitalmars-d
mailing list