From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a1a88c4d509f6381 X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: scope and/or parameters (beginner) Date: 1999/04/13 Message-ID: <7evbei$opm$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 465842065 References: <37064309.889106243@news.dsuper.net> <37084459.8616007@rocketmail.com> <370b0c99.1137352783@news.dsuper.net> <7ei04q$o$1@nnrp1.dejanews.com> <7et4vr$sdj$1@nnrp1.dejanews.com> <7euskv$d91$1@nnrp1.dejanews.com> X-Http-Proxy: 1.0 x13.dejanews.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Tue Apr 13 11:57:09 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-04-13T00:00:00+00:00 List-Id: In article <7euskv$d91$1@nnrp1.dejanews.com>, czgrr wrote: snipped: <> One comment in particular: > So there is a definite difference between the time taken > to call a routine with and without local variables, > albeit very small. This is plain wrong on many machines. There is no difference. Furthermore, just because you don't WRITE any local variables does not mean there are none in the generated code. > > Now, back to nested subroutines... > > I would guess that the elaboration process works the same > way. Every time a routine is called, any elaborations for > local declarations take place. Why on earth is a guess required? Yes this is true, but it is simply a function of the language in question (go look at the GNU C definition, or the Ada or Pascal standards for example). > When you first run an executable, there is work going on > before reaching the first line of the main program which > elaborates everything which is global in > all the packages. What this elaboration involves is highly language dependent. For example, in C, there is no runtime activity at all from this elaboration. > But this happens only once. So making > as much as you can be > global will improve overall run-time performance This is in general quite wrong. Access to local variables on the stack is generally much more efficient than access to global variables on modern architectures. > Incidentally, it is *definitely* worse to have local > procedure or package > declarations which come about using NEW. I always make > them global to the > calling package. Put them in a low level, > frequently-called routine and it can > kill your performance, and that's from experience. No, it is from a misreading of experience, local procedures cannot affect performance in this manner in any reasonable implementation. Indeed since you cannot use "new" with procedures except in a generic context it is not clear what you are talking about at all. Whether something needs to be global or local (in lifetime or scope) is a logic issue in a program, and not an efficiency issue that a programmer should worry about. Programmers who molest their programs in the interests of efficiency almost always get things wrong, and often make things worse! A little knowledge can be worse than none in this area.h Robert Dewar -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own