Complex.c

Norbert Nemec Norbert at Nemec-online.de
Mon May 1 09:44:53 PDT 2006


Craig Black wrote:
> 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.

Call by reference may be faster if the value is already stored in memory
or is still needed after the function call. Consider, however:

	a = myfunction(b + c);

Here, the value of b + c is calculated and only used for calling the
function. Call-by-value allows the compiler to store the value directly
in the place where it is needed by the function, which definitely is
faster than having to store it in a local variable and then again having
to dereference a pointer to that variable.

It really is a trade-off that cannot be decided without looking at given
use cases.



More information about the Digitalmars-d mailing list