String/array memory usage

Just starting out? Need help? Post your questions and find answers here.
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

String/array memory usage

Post by jesperbrannmark »

Hi.
This might seem like an odd request because normally this is stuff you should keep track off while developing...
But my program just recently went from 2 MB RAM usage to 90 MB. On a modern PC that is not noticed, but on a five year old that really affects the user experience.

So my question is:
Is there a easy way to list all arrays/maps/lists used and see their memory usage so I can see which one is taking up all that memory?
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: String/array memory usage

Post by citystate »

put in a breakpoint and use the variable viewer? (I think it gives some info on lists and arrays, so I guess it might do maps too)
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
infratec
Always Here
Always Here
Posts: 7628
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: String/array memory usage

Post by infratec »

Hi,

add a keyboard shortcut and than build a Text$ with the help of ArraySize() ListSize() and MapSize()
and at least use MessageRequester() to show the values.

Bernd
jesperbrannmark
Enthusiast
Enthusiast
Posts: 536
Joined: Mon Feb 16, 2009 10:42 am
Location: sweden
Contact:

Re: String/array memory usage

Post by jesperbrannmark »

I see my problem is in a array (probably) like one of those

Code: Select all

global dim jesper.s(999,99)
With the ones that are integer, long etc i have no problem figuring out the size of them, but with strings - is there a smart way?
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: String/array memory usage

Post by Shield »

You need to iterate through the array and sum up the length of each string. Also don't forget to add the memory required for the pointers
to actually reference the strings. :) I don't think there is any other way.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: String/array memory usage

Post by RASHAD »

For Windows

1- Include the next code into a Procedure
2- Call the Procedure after each use of ( Arrary,LinkedList,Map,.... )
3- Write the result to a Log File

You can get the memory hungry act from the log

Code: Select all

Memory.MEMORYSTATUSEX
Memory\dwLength.l = SizeOf (Memory)
GlobalMemoryStatusEx_(Memory.MEMORYSTATUSEX) 
Debug "Available Physical Installed   : "+Str(Memory\ullAvailPhys.q /1024/1024) + "   MB"
Debug "Free of Paging File                : "+Str(Memory\ullAvailPageFile.q/1000000)
Egypt my love
Post Reply