assignment and copy constructors

From: Sean Dettrick (sdettrick_at_hotmail.com)
Date: 05/27/04

  • Next message: Toon Moene: "Re: OT: Re: Fortran 95/2003 Explained -- due in Sep '04"
    Date: 27 May 2004 11:00:25 -0700
    
    

    Hi,
    I was wondering, is there an efficiency penalty when using an
    array-valued function instead of a subroutine? For example:

       function deriv( F )
         real, dimension(100) :: F, deriv
         deriv = 0.5 * ( eoshift( F, 1 ) - eoshift( F, -1 ) )
       end function deriv

       subroutine deriv( F, dFdr )
         real, dimension(100) :: F, dFdr
         dFdr = 0.5 * ( eoshift( F, 1 ) - eoshift( F, -1 ) )
       end subroutine deriv

    I know in C++ the function version is much less efficient, because the
    function statement:
       dFdr = deriv( F )
    has to call a constructor to create DERIV inside the function, then do
    the calculation, then call a copy constructor to copy DERIV into dFdr.
      In contrast, the subroutine version:
       call deriv( F, dFdr )
    needn't perform any constructor operations if the arrays are passed by
    reference or pointer.

    I understand Fortran passes all arguments by reference, so I needn't
    worry about that, but what about the function assignment??? Is
    fortran "smart" enough to do that by reference too?

    Thanks,
    Sean


  • Next message: Toon Moene: "Re: OT: Re: Fortran 95/2003 Explained -- due in Sep '04"