Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
how to know if heap spaces is exhausted?

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
stevech



Joined: 23 Feb 2006
Posts: 657

Posted: 18 September 2006, 3:08 AM    Post subject: how to know if heap spaces is exhausted? Reply with quote

I have a situation where my program fails and I suspect it's because there's not enough RAM to create another string and my program is unaware. The result is that my program fails.

Diagnosis (I hope I'm correct)...
a task computes a string and stores this in a local variable named s, of type string.
This string is then sent to console.writeline() and buffered in RAM.
next it is used like this:
myString(i) = s
where myString() is a module global
this would make a copy of s in new RAM.

My testing shows that I'm managing the array index correctly.
If i change the code to say
myString(i) = left(s, 40)
then my program does not fail.

So I think the VM is running out of RAM . The problem arises for i = 8 where each string is about 60 bytes. That's probably too much.

I printed out register.ramUsed and I see 657 of 1536 (ramSize). That 657 does not ever change value; same numbers when my main() starts up. Perhaps because the heap starts at some initial size. I speculate that when the initial heap size is exhausted due to my storage of strings in this array, something goes wrong with future allocation from the remaining 1536-657 bytes of unused RAM.

Another possibility is that I am making a dumb mistake.

Maybe register.ramUsed is the RAM for static variables only and I need to look at register.heapSomethingOrAnother
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 18 September 2006, 3:33 AM    Post subject: Re: how to know if heap spaces is exhausted? Reply with quote

stevech wrote:
So I think the VM is running out of RAM . The problem arises for i = 8 where each string is about 60 bytes. That's probably too much.

It all depends on how much RAM is being used for statically allocated variables and the stack. Register.RamUsed only indicates the static use. Space for the Main() task stack and strings is added to that.

The value Register.HeapEnd gives the lowest address in use by the heap which grows toward zero. Register.UserSP gives the stack pointer value for the task from which it is referenced. This value grows toward the heap. Problems will begin to manifest when these two values meet.

The discussion above applies to VM v1.3 and later. Prior to that, the string heap was located in the "system" area of RAM - the upper 1K of RAM.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group