comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <robert_dewar@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: <7evbei$opm$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 7euskv$d91$1@nnrp1.dejanews.com

In article <7euskv$d91$1@nnrp1.dejanews.com>,
  czgrr <czgrr@my-dejanews.com> wrote:

snipped:
<<quite a bit of stuff based on guesses from "what he
  remembers about how compilers work". Quite a bit is
  wrong or at least misleading.>>

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    




  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
1999-04-13  0:00           ` Robert Dewar [this message]
1999-04-14  0:00             ` czgrr
1999-04-14  0:00               ` Robert Dewar
1999-04-15  0:00                 ` czgrr
1999-04-15  0:00                   ` Robert Dewar
1999-04-14  0:00               ` dennison
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                       ` dennison
1999-04-15  0:00                       ` Hyman Rosen
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