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=-0.3 required=5.0 tests=BAYES_00,HK_RANDOM_FROM, 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: czgrr Subject: Re: scope and/or parameters (beginner) Date: 1999/04/13 Message-ID: <7euskv$d91$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 465787198 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> X-Http-Proxy: 1.0 x8.dejanews.com:80 (Squid/1.1.22) for client 193.192.234.4 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Tue Apr 13 07:44:32 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT) Date: 1999-04-13T00:00:00+00:00 List-Id: In article <7et4vr$sdj$1@nnrp1.dejanews.com>, dennison@telepath.com wrote: [snip] > It was claimed here at work that nested subroutines should be avoided due to > the elaboration overhead whenever the outer routine is called. That sounds a > bit shaky to me. Is there a situation where there would be a runtime impact > of nesting subroutines? Forgetting about nested subroutines for the moment... >From what I remember about how compilers work, when you call a routine, stack is allocated for parameters, local variables, and the like. Run-time info for the calling routine is saved. Implicit initialisation might also occur here. This happens every time you make a procedure or function call. The reverse (less work, but still work) occurs when the routine finishes. If the local variables were declared globally, the space is taken once only when the program is first run, or in fact might even allocated in part of the executable itself. No implicit initialisations. There is still an overhead in calling a routine, but it is less. So there is a definite difference between the time taken to call a routine with and without local variables, albeit very small. 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. 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. But this happens only once. So making as much as you can be global will improve overall run-time performance (which I am not recommending in the general case, BTW), and the amount of saving (i.e. worth it, not worth it) depends on exactly what your program is doing and how it is structured. In the end, I expect it's down to the compiler. The optimisation stage of a good compiler may well completely eliminate any overhead from nested subroutines, and using PRAGMA INLINE can reduce general calling overheads. 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. -- My opinions, suggestions, etc, are not necessarily those of my employer. They might not even be right. Use at your own risk. -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own