|
|
| 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? |
|
|
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? |
|
|
| 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 |
|
 |
|