global variables vs. custom properties
Jim Ault
JimAultWins at yahoo.com
Fri Jan 16 10:41:20 EST 2009
There are also a drawbacks to gobals when designing reuseable functions
If there is a global you like to use, say gRawTextString and
gFormattedTextString, you could have situations where two different stacks
you are developing are using the same names. This means that script
debugging can be made more difficult if both stacks are open.
One situation where this occurs is when you make your own Ask, Answer dialog
boxes and put them in to different stacks. Another is when you make plugin
stacks of your library routines.
A specific example for me is the management of sockets in some of my
networking apps. Things like StartUDP, StopUDP, gHostIP, gServerList,
gFTPaddressWithLoginPswd, StartTcpIpSession, gIsRunning, gPacketToSend will
obviously not work properly if I have two or more communication stacks open.
Custom properties are good in those situations because then either have
specific, unambiguous locations or are assumed to be local (eg.
on opencard
set the cpsTimeData["cpFirstOpened"] of this card to the seconds
Since globals are in memory space that is owned by Revolution and not the
stack or library/plugin script that uses them, they don't die until you quit
Revolution (large variable sizes remain in memory). A custom property is
put into memory when the stack is opened, then purged when closed.
A little more info for that might help.
Jim Ault
Las Vegas
On 1/16/09 7:00 AM, "Rob Cozens" <rcozens at pon.net> wrote:
> Hi Tiemo,:
>
>> I know, that most people prefer custom properties, but is it just a question
>> of "school", or is there perhaps a difference in memory usage or other "hard
>> facts"?
>
> Custom properties are stored within the stack file when it is saved,
> whereas globals die when the Rev engine or your standalone quits.
>
> So if your variables are non-persistant, then globals better fulfill
> that function. If you have variables that are populated after
> startup and don't need to persist after shut down, putting them in
> custom properties simply increases the physical size of the stack
> file for no useful purpose.
>
>
>
> Rob Cozens CCW
> Serendipity Software Company
>
> "And I, which was two fooles, do so grow three;
> Who are a little wise, the best fooles bee."
>
> from "The Triple Foole" by John Donne (1572-1631)
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
More information about the use-livecode
mailing list