Complex.c

Craig Black cblack at ara.com
Sun Apr 30 15:47:02 PDT 2006


"Ben Phillips" <Ben_member at pathlink.com> wrote in message
news:e33d7q$2u15$1 at digitaldaemon.com...
> In article <e33at8$2r49$1 at digitaldaemon.com>, Craig Black says...
> >
> >I notice that there was both C and D source in the phobos internal
library
> >code.  Anyone know why?
> >
> >Another thing ... I looked at complex.h and noticed that the functions
were
> >passing Complex by value.  That is not as efficient as using references
for
> >a data structure with 2 long doubles.  Given that a long double is 80
bits,
> >and each needs to be aligned appropriately, the Complex data structure is
at
> >least 8 bytes long.  So it seems that passing by reference would be
faster,
> >but maybe I'm missing something.
> >
> >-Craig
> >
>
> I believe its because types such as creal and such are primitives and are
> allocated on the stack.

It doesn't matter whether you are on the stack or on the heap.  If you pass
a data structure by value, then you are pushing and popping the entire
contents of the data structure onto the stack every time you call the
function.  I've run benchmarks and it is much better to pass by reference,
especially for large data structures.

-Craig





More information about the Digitalmars-d mailing list