1. RE: Penalty for using globals?

SR.Williamson wrote:
> What kind of penalty can I expect from using a lot of global variables 
> or sequences? Speed? Memory use?
> 
> 
> 

if you define a variable inside a function , it exists while that 
function is running. it is deleted from the programs 'address' space 
when that function is finished. you would probably get a penalty in time 
if you are frequently creating and destroying the same variable. if you 
define it outside all your functions , it uses some address space while 
your program runs but is available to any of the functions that need it 
at any time.
thats where the programmer has to make compromised performance 
decisions.  each program(problem) has it own factors to determine the 
best direction to go. just like having to decide to hold data in memory 
or on disk while program is running. not everyone has the same amount of 
memory in their system so your program might run fine on your system but 
crash on their system if you make everything stay in memory. 
hope this helps somewhat.

later
rudy
rltoews at ilos.net


lotterywars

new topic     » topic index » view message » categorize

2. RE: Penalty for using globals?

SR.Williamson wrote:
> What kind of penalty can I expect from using a lot of global variables 
> or sequences? Speed? Memory use?
> 
> 
>

There must be some speed/memory loss but both must be negligable. If 
writting big apps that have lots of include files then the only problem 
you'll face is confusion or naming conflicts.

jordah

new topic     » goto parent     » topic index » view message » categorize

3. RE: Penalty for using globals?

One of the things I found when writing programs in Pascal (before I had
found Euphoria) was that most of my programs contained one or two master
arrays that needed to be accessed or adjusted by virtually every routine
in the program.  For those master arrays (i.e., the checkerboard in a
checkers game), it made more sense to declare them as global and comment
each routine that was modifying the array globally.  Especially for
large arrays, the benefits included faster code and better memory use
(not needing to copy the whole array twice just to change one element
and less typing.

In Euphoria, the penalty for passing a large sequence to a routine is
zero, until the routine modifies the sequence.  For that reason, I
continue to use global variables for master sequences and routine flags
(such as those that indicate when a dialog is open in a Windows
program).  Depending on the size of the program, all other variables
should either be local to the file or local to each routine.  File
pointers in particular are best passed to each routine <disclaimer: good
advice applies equally to the giver as to the recipient <G>>.  Overuse
of global variables is as much an enigma to good programming as the
overuse of goto.  As a general rule, only globalize those variables that
are large and will be modified by many different routines, or those
variables that need to be seen across several files.  As much as
possible, strive to use as few globals as possible.  Oh, and don't
forget to document liberally blink.

Michael J. Sabal

>>> jorfergie03 at yahoo.com 06/17/02 10:21AM >>>

SR.Williamson wrote:
> What kind of penalty can I expect from using a lot of global
variables 
> or sequences? Speed? Memory use?
> 
> 
>

There must be some speed/memory loss but both must be negligable. If 
writting big apps that have lots of include files then the only problem

you'll face is confusion or naming conflicts.

jordah

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu