comp.lang.ada
 help / color / mirror / Atom feed
From: czgrr <czgrr@my-dejanews.com>
Subject: Re: scope and/or parameters (beginner)
Date: 1999/04/13
Date: 1999-04-13T00:00:00+00:00	[thread overview]
Message-ID: <7euskv$d91$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 7et4vr$sdj$1@nnrp1.dejanews.com

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    




  reply	other threads:[~1999-04-13  0:00 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-02  0:00 scope and/or parameters (beginner) fluffy_pink
1999-04-03  0:00 ` Matthew Heaney
1999-04-05  0:00 ` Corey Ashford
1999-04-05  0:00   ` fluffy_doo
1999-04-06  0:00     ` Matthew Heaney
1999-04-08  0:00     ` czgrr
1999-04-10  0:00       ` fluffy_puff
1999-04-12  0:00       ` dennison
1999-04-13  0:00         ` czgrr [this message]
1999-04-13  0:00           ` Robert Dewar
1999-04-14  0:00             ` czgrr
1999-04-14  0:00               ` dennison
1999-04-14  0:00               ` Robert Dewar
1999-04-15  0:00                 ` czgrr
1999-04-15  0:00                   ` Robert Dewar
1999-04-13  0:00         ` Robert Dewar
1999-04-13  0:00     ` Robert A Duff
1999-04-14  0:00       ` Robert Dewar
1999-04-14  0:00         ` Hyman Rosen
1999-04-14  0:00           ` dennison
1999-04-14  0:00             ` Hyman Rosen
1999-04-14  0:00               ` dennison
1999-04-14  0:00                 ` Hyman Rosen
1999-04-15  0:00                   ` dennison
1999-04-15  0:00                     ` Robert Dewar
1999-04-15  0:00                       ` Hyman Rosen
1999-04-15  0:00                       ` dennison
1999-04-15  0:00           ` Robert Dewar
1999-04-15  0:00             ` Hyman Rosen
1999-04-15  0:00               ` Robert Dewar
1999-04-15  0:00                 ` Hyman Rosen
1999-04-16  0:00               ` Rakesh Malhotra
1999-04-15  0:00       ` fluffy_dong
1999-04-15  0:00         ` Robert Dewar
1999-04-15  0:00           ` dennison
1999-04-15  0:00             ` fluffy_dong
1999-04-16  0:00               ` Robert Dewar
1999-04-16  0:00                 ` Fraser Wilson
1999-04-16  0:00                   ` Gautier.DeMontmollin
1999-04-20  0:00                     ` Nick Roberts
1999-04-21  0:00                     ` fraser
1999-04-22  0:00               ` Robert A Duff
1999-04-22  0:00                 ` Larry Kilgallen
1999-04-16  0:00         ` Samuel Mize
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox