Page 1 of 1

globals memory use

Posted: Wed Feb 04, 2015 1:01 am
by adventuresofgreg
Hi - I need to check the growth (size) of my global variables, so I wrote a handler to do this, but it doesn't use the global name, it uses the literal word. Any ideas how to get around this?

on memcheck
put the globalnames into Gnames
repeat for each item myitem in Gnames
put myitem & tab & the number of bytes of myitem & return after memlist
end repeat
set the itemdelimiter to tab
sort lines of memlist numeric descending by item 2 of each
put memlist into field "theglobals" on stack "G59BlackBox"
end memcheck

Re: globals memory use

Posted: Wed Feb 04, 2015 1:07 am
by adventuresofgreg
I tried using value(myitem) but that doesnt work - I still get the number of bytes of the global WORD rather than the number of bytes of the actual global variable

Re: globals memory use

Posted: Wed Feb 04, 2015 2:12 am
by dave.kilroy
Hi Greg - you were right to use value(), you just have to do it in two steps...

Code: Select all

on memcheck
   put the globalnames into Gnames
   repeat for each item myitem in Gnames
      put value(myitem) into myBytes
      put myitem & tab & (the number of bytes of myBytes) & return after memlist
   end repeat
   set the itemdel to tab
   sort lines of memlist numeric descending by item 2 of each
   put memlist into field "theglobals" on stack "G59BlackBox"
end memcheck

Re: globals memory use

Posted: Wed Feb 04, 2015 5:14 pm
by adventuresofgreg
Hi Dave. For some reason, that only works on the first couple of globals. The rest of the globals in the list are the number of bytes of the global NAME, just like before. Strange...

Here is the list of returned global names with the # bytes per global:

Tdata 249671
Xconsole 4264
SymbList 55
$TMPDIR 49
$PATH 29
BadG59List 28
$SSH_AUTH_SOCK 28
gREVAllowSaveStackRequest 25
$LOGNAME 16
$USER 16
ResultsDBmaster 15

If I type "put the number of bytes of ResultsDBmaster" into msg box, it returns 403000, which is correct. Yet the handler returns 15 which is the number of bytes of the WORD "ResultsDBMaster". Yet, Tdata and Xcolsole are correct. Any ideas?

Greg

Re: globals memory use

Posted: Wed Feb 04, 2015 11:09 pm
by dave.kilroy
Hi greg -

If I have the following script inside btn "btnSetup" to set up and populate 14 globals:

Code: Select all

global gA,gB,gC,gD,gE,gF,gH,gI,gJ,gK,gL,gM,gN
on mouseUp
   put "abc-1" into gA
   put "abc-12" into gB
   put "abc-123" into gC
   put "abc-1234" into gD
   put "abc-12345" into gE
   put "abc-123456" into gF
   put "abc-1234567" into gG
   put "abc-12345678" into gH
   put "abc-123456789" into gI
   put "abc-1234567890" into gJ
   put "abc-12345678901" into gK
   put "abc-123456789012" into gL
   put "abc-1234567890123" into gM
   put "abc-12345678901234" into gN
end mouseUp
and the following script like we had before inside the script of a separate btn "btnShow":

Code: Select all

on mouseUp
   memcheck
end mouseUp

on memcheck
   put the globalnames into Gnames
   repeat for each item myitem in Gnames
      put value(myitem) into myBytes
      put myitem & tab & (the number of bytes of myBytes) & return after memlist
   end repeat
   set the itemdel to tab
   sort lines of memlist numeric ascending by item 2 of each
   answer memlist
end memcheck
Then all I get is the number of bytes in the name of the global. However if I declare these globals in the script of btn "btnShow" then all 14 of them correctly report the number of bytes in them.

So what happens if you declare your 'ResultsDBmaster' global before running your memcheck handler?

Dave

Re: globals memory use

Posted: Wed Feb 04, 2015 11:18 pm
by adventuresofgreg
ok - sorry. My problem was that i wasnt declaring the globals before using value(global). The value of myGlobal is nothing is my handler doesn't know myglobal is indeed a global. :-)

Re: globals memory use

Posted: Wed Feb 04, 2015 11:21 pm
by dave.kilroy
Yes I think you're right - it does seem a bit non-intuitive though and there are obviously two 'classes' of globals - the ones we create and the ones LiveCode does...

Re: globals memory use

Posted: Thu Feb 05, 2015 1:47 am
by adventuresofgreg
A new problem though... any idea why this script would not work in a windows standalone? It's the exact same script, everything, but doesnt do anything in my standalone app, but works perfectly in Livecode.

Re: globals memory use

Posted: Thu Feb 05, 2015 9:45 am
by dave.kilroy
Hi Greg

Sorry don't know why it's not working on a Windows standalone. I've just tested the 'two button' script in a standalone on a mac it worked fine - not close to a windows box at the moment to test with ... are you sure the globals you want are declared properly in each script where they are needed? Maybe try my 'two button' scripts?

Dave

Re: globals memory use

Posted: Thu Feb 05, 2015 11:34 pm
by adventuresofgreg
I bet it isn't working due to the scripting limits in standalones. maybe? that's the only reason I can think of as to why something would not work in a SA

Re: globals memory use

Posted: Thu Feb 05, 2015 11:39 pm
by dave.kilroy
hmm not sure about that, scripting limits have been removed in standalones - may be something specific to Windows platform...

What about if you declare and call globals normally (without use of globalnames) in your standalone?

Re: globals memory use

Posted: Fri Feb 06, 2015 9:21 am
by Thierry
adventuresofgreg wrote:.... why something would not work in a SA
If you feel so you could try this:

- in your IDE, go to Preferences->Script Editor and uncheck Variable preservation

- restart the IDE to start again with a clean context.

Is your script reading the globals still working in the IDE?

The idea behind this is a typo somewhere within your code ( variable name) and that the IDE
keep the old *good* variable name, lost in your SA... :roll:

Regards,

Thierry