On Sunday, 14 December 2014 at 22:14:55 UTC, Ryan wrote:
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,

Just a hint about "a LOT of work":

----------
struct Hop {

version(noGC) // defined with a custom compiler switch -version=noGC
    private T[] arr;
  else
    std.container.Array!T arr;

}
----------

The GC-free array already exist in the standard library.

Reply via email to