slow runtime

Jonathan M Davis jmdavisprog at gmail.com
Thu Sep 9 21:03:30 PDT 2010


On Thursday 09 September 2010 20:54:15 Dr. Smith wrote:
> Jonathan, thank you for the quick response.  I made some changes as you
> suggested and got much more speed. For some code that I'd like to convert
> to D, I am exploring the pros and cons of constructing a class library
> (versus a C like function library). My code here is just part of that
> exploration.
> 
> ... the improved calling code ...
> 
> import std.stdio, std.string;
> import testlib;
> 
> void main() {
> 
>   classtest obj = new classtest;
>   double[][] a = obj.hit;
>   double[][] b = obj.hot;
>   string c = obj.stest;
> 
>   int i, j;
> 
>   for(i = 1; i < a.length; i++) {
>     for(j = 1; j < a[i].length; j++) {
>       writefln("%s\t%f\t%f", c, a[i][j], b[i][j]);
>     }
>   }
> }

The other thing to consider is structs vs classes. Structs are value types which 
live on the heap and have no inheritance or polymorphism. Classes are reference 
types which live on the heap and have both inheritance and polymorphism. The 
general rule is to make something a struct unless you need inheritance and 
polymorphism (though obviously other things make factor into that choice).

Also, if you're serious about learning D, I'd definitely recommend picking up 
Andrei's book, "The D Programming Language." It's far more detailed and up-to-
date than any of the online docs (though dmd isn't quite yet up-to-date in 
comparison to the book on all counts - the @property issue that you ran into 
being one). If you're just dabbling in D, it may not be worth the cost, but if 
you really want to be using D, then I think that it's well worth the cost.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list