Get the size of (part of) an array in memory?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Fjord
Posts: 145
Joined: Sat Dec 06, 2008 6:18 pm

Get the size of (part of) an array in memory?

Post by Fjord » Fri Dec 06, 2024 6:42 pm

Hi, all

I know one can get the length of an arrayEncoded array. But I wonder how to get the size in memory of an arrayDecoded array. My preOpenStack handler contains

Code: Select all

global stackData
put arrayDecode(URL anURL) into stackData -- previously encoded array data
My data in memory is now a tree that's 5 levels deep which is OK. It happens the disk file is 5,4Mo, which seems an awful lot. I want to find what's wrong with the data in the array. The debugger keeps displaying empty windows whenever I try to display the last level of data.
Is that normal?

I want to locate the part of the tree that I suspect is bloated. I can do

Code: Select all

global stackData
answer len(arrayEncode(stackData))
but not knowing HOW the data is encoded, this is not really informative. I would like to do something like

Code: Select all

global stackData
answer size(stackData) -- gives an error
answer len(stackData) -- returns 0
answer len(stackData[subtreeLevel1]…etc) -- returns 0
Any way to do this?
--
François

bwmilby
Posts: 462
Joined: Wed Jun 07, 2017 5:37 am
Contact:

Re: Get the size of (part of) an array in memory?

Post by bwmilby » Sat Dec 07, 2024 1:42 am

You could iterate over the keys at the first level and get the size of each sub-array via encoding. Then you could do the same for the largest key at the next level and so on (if size would point to a possible issue).

Another option is to just use the tree widget to display the data and you can browse it pretty easily.

You mentioned blank windows from debugger but didn’t really cover how you were using it to view.

Fjord
Posts: 145
Joined: Sat Dec 06, 2008 6:18 pm

Re: Get the size of (part of) an array in memory?

Post by Fjord » Sat Dec 07, 2024 4:16 pm

get the size of each sub-array via encoding
I'm not sure I understand what you mean by 'encoding'…? if you mean using the command 'arrayEncode', that's what I would like to avoid: I need to (well, would like to) get the space in memory, because I don't know how an array is compacted when it is 'encoded'
blank windows from debugger
I meant just that: displaying the tree in the debugger just displays blank windows with the address on top.
Actually I found some items of the array are a few megabytes (which is not normal in that case). Maybe this is a cause for that empty window…
Screenshot.gif
--
François

Post Reply