Global variables
#5

Whichever way you decide to approach this, either allocate space on the stack in every function or use globals which should be kept in a special area called the data segment, you need to be careful.

With global arrays/variables, you could face value corruption issues (function 1 uses this array, and calls function 2 which also uses this array for something else, after function 2 execution function 1 wants to do something with the array, but it has been changed resulting in behavior that you do not seek).
With locals, you could face stack overflow when a function calls itself for example or if the chain of functions is really long (function 20, which allocates variables on stack, is called by function 19, which allocates ..., is called by function 18, ...., ... by function 17, ... function 1) since stack behaves like a last-in-first-out queue.

There are some specifics I won't go into as I'm not sure if they apply fully on PAWN and AMX, but this should give you a good idea of what you need to watch out for.

// Edit: About the original question - I do that as well. I have a few larger global arrays. And I've faced problems before due to not being careful enough :P
Reply


Messages In This Thread
Global variables - by dusk - 20.07.2013, 06:43
Re: Global variables - by RajatPawar - 20.07.2013, 06:49
Re: Global variables - by dusk - 20.07.2013, 07:03
Re: Global variables - by RajatPawar - 20.07.2013, 07:09
Re: Global variables - by AndreT - 20.07.2013, 07:27
Re: Global variables - by dusk - 20.07.2013, 07:30
Re: Global variables - by MP2 - 20.07.2013, 07:53
Re: Global variables - by AndreT - 20.07.2013, 07:54
Re: Global variables - by dusk - 20.07.2013, 09:14
Re: Global variables - by iggy1 - 20.07.2013, 09:21

Forum Jump:


Users browsing this thread: 1 Guest(s)