Re: VB 6.0 Desktop - Global Variables
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Thu, 9 Feb 2006 19:06:01 -0500
"Ulrich Korndoerfer" <ulrich_wants_nospam@xxxxxxxxxxxx> wrote in message
news:43EAA4C8.3000409@xxxxxxxxxxxxxxx
Hi,
MikeD schrieb:
...
So, the performance of global variables are slower than local variables.
Why? the extra-logic work that compiler has to do.
No. Performance should not be affected in any measurable way (from a
user perspective). Now, *memory* usage might be affected, but global
variables are not "slower" than local variables. As has been stated,
global variables tend to make maintainability much more difficult and,
IMO, make bugs much more likely (and more difficult to solve).
It depends on what one means with "global". If it is meant "having project
wide scope", then this kind of variables only can live in a module. Making
them local by giving them the attribute Private and giving acces by
property only or moving it into a class, then access will be (much)
slower!
Well, I consider a "global variable" (and even just "global" by itself) to
mean a variable declared using either the Global or Public keyword in a
standard code module. As you say, having project wide scope, but also
without needing a reference to an object. A variable that is declared
Private and has a property which publicly exposes it is not, IMO, global in
any way because it's encapsulated by the object. You need a reference to
that object to use it. If you don't have that reference, it's not
accessible. So how can that be considered global?
Now, as far as speed/performance:
I said "in any measurable way (from a user perspective)".
Sure, if you actually want to benchmark (done properly) any speed difference
in global variables vs. module-level or local variables or wrapping a
module-level variable in a property procedure, I suppose it is probably
measurable. The difference is going to be so small though that proper scope,
not to mention maintainability and all other benefits associated with using
the right scope (which goes hand-in-hand with writing good, clear, legible
code), is considerably more important than the few CPU cycles you'll save by
inundating your program with dozens or hundreds of global variables.
Everybody is so concerned with "speed". Sure, that's important and
something that needs to always be taken into consideration. But what's more
important (and ultimately is what really matters most) is "apparent speed"
from a user perspective.
--
Mike
Microsoft MVP Visual Basic
.
- Follow-Ups:
- Re: VB 6.0 Desktop - Global Variables
- From: Ulrich Korndoerfer
- Re: VB 6.0 Desktop - Global Variables
- References:
- VB 6.0 Desktop - Global Variables
- From: isicoder
- Re: VB 6.0 Desktop - Global Variables
- From: Harvey Triana
- Re: VB 6.0 Desktop - Global Variables
- From: MikeD
- Re: VB 6.0 Desktop - Global Variables
- From: Ulrich Korndoerfer
- VB 6.0 Desktop - Global Variables
- Prev by Date: Re: Confused: Updating VB6
- Next by Date: Re: GetPrivateProfileString() retrieves data but strips "", ????
- Previous by thread: Re: VB 6.0 Desktop - Global Variables
- Next by thread: Re: VB 6.0 Desktop - Global Variables
- Index(es):
Relevant Pages
|