Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!ll-xn!oberon!sdcrdcf!hplabs!hp-sdd!ncr-sd!crash!jeh From: jeh@crash.cts.com (Jamie Hanrahan) Newsgroups: comp.os.vms Subject: Re: 2 C questions Message-ID: <2776@crash.cts.com> Date: 6 Apr 88 19:27:08 GMT References: <12387779883.20.STEINBERGER@KL.SRI.COM> <281@cullsj.UUCP> Reply-To: jeh@crash.CTS.COM (Jamie Hanrahan) Organization: CMKRNL Press, San Diego, CA Lines: 38 Summary: It's a wash. In article <281@cullsj.UUCP> jayz@cullsj.UUCP (Jay Zorzy) writes: >From article <12387779883.20.STEINBERGER@KL.SRI.COM>, by STEINBERGER@KL.SRI.COM (Richard Steinberger): >> C vs. Fortran speed: Since C variables are automatic (i.e., dynamic) by >> default and Fortran variables are static, is it fair to conclude that in >> general, a routine in C having the same number of local variables as >> a "roughly identical" Fortarn routine will take a bit longer because >> the OS must allocate (and deallocate) space for the local variables? >> If the C local variables are made static, does this possible performance >> advantage disappear? > >It depends on the size of the variables. Dynamic variables are allocated >from the stack, so if you've got huge arrays, VMS will obviously have more >work to do to allocate them on the stack. Another point to consider, is >that static variables are allocated during image activation in R/W, copy- >on-reference (CRF) sections. Depending on the frequency these sections >are accessed, you may have paging activity to consider. > Er, no. The job of allocating the space on the stack is accomplished by a single SUBL2 instruction -- the stack pointer value is decremented by the number of bytes in the dynamic variables. All references to such variables are handled as displacements from either the SP or another register in which the appropriate value of the SP is stored (this because other things might be pushed on the stack). The stack is in a copy-on-reference section just like Fortran static variables are; offhand I'd say the number of page faults would be similar for similarly-designed programs. Another question in the original posting had to do with the efficiency of pass-by-reference (Fortran default) vs. pass-by-value (C default). It will take longer for the called procedure to pick up an argument passed by reference, as one additional fetch is required. On the other hand, if we're comparing C to Fortran, recall that C always pushes its argument lists on the stack and uses CALLS, while Fortran allocates static argument lists, modifies only those arguments that need to be modified at runtime, and uses CALLG. So if your argument list has nothing that needs to be evaluated at runtime (an array element with a non-constant subscript, for instance), the Fortran call will be faster. Now you get to worry about frequency of procedure call vs. frequency of the procedure's access to its arguments...