Fast matrix struct

Ryan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Dec 14 14:14:54 PST 2014


I'm writing a Matrix struct that I plan to use for some number 
crunching, which will be intensive at times. So I want it to be 
fast.

Will I do better by manually managing the memory myself with 
malloc and free in the constructors/destructor or just using 
plain D arrays?

The manual way I could bypass the GC and bounds checks. I don't 
need (or want) any of the fancy appending concatenation and the 
potential slowdowns from the heap allocations that comes with the 
builtin arrays.

But I have to wonder, if I just don't use those features, will it 
be just as fast with the GC (assuming I compile out the bounds 
checks with the -release compiler option)?

Right now my strategy is to malloc one large chunk of memory in 
the constructor (and postblit) and treat the 2-d matrix as a 1-d 
array internally. Then just use pointer arithmetic to access the 
elements.

I know the best way to know is just to test. But writing both 
versions would take a LOT of work, and I'm looking for guidance 
about which path will probably be most fruitful.

Thanks,


More information about the Digitalmars-d-learn mailing list