Old problem with performance

Rainer Deyke rainerd at eldwood.com
Thu Feb 12 18:46:56 PST 2009


Daniel Keep wrote:
> It's not a bug.  There are differences between value types and reference
> types.  Just like how there are differences between atomic types and
> aggregate types.  Or constant types and mutable types.

This is a bug:

struct MathematicalVector {
  this(int size) {
    this.values = new T[size];
  }
  // No copy constructor.
  // Insert standard mathematical operators here.
  private T[] values; // Implementation detail.
}

I want MathematicalVector to be a value type (which is why I declared it
as a struct).  However, it doesn't behave a value type because I forgot
to write the copy constructor.  D doesn't cause the bug, but it
certainly makes it easier to accidentally write this kind of bug.

By contrast, the compiler-generated copy constructors in C++ usually do
the right thing for all but a handful of low-level resource-management
classes.  Which is not to say that C++ doesn't have problems of its own
- clearly it does, or I wouldn't be looking at D.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list