Object Exceeds Runtime memory limit by x longs
JD
Posts: 570
Hello All, hope all is well :cool:
I have run into a strange issue compiling with my latest project. As the program grew in size, I had to save some space so it would compile. I thought moving all the variables (offset, offset2, offset3) from the local level and use 3 global bytes would save space. It went from some 60 bytes to 3, how could it not right? Nope, something with a miss... haha
The image below is a screenshot of when I try to compile for each version of code. One doesn't use global vars and one that trys to. The one without compile with 718 longs in change, and the other using global variables does not compile. Anyone have an idea? I saw the other thread but didn't get an answer or perhaps just missed it thinking it was something else.
The code Im working on is private sensative so sorry I can't upload it to have others to try to compile to make sure there isn't some comma or something I missed. I believe I found a strange thing; I am oddly good at these. haha :thumb:
Thanks for the help,
JD
I have run into a strange issue compiling with my latest project. As the program grew in size, I had to save some space so it would compile. I thought moving all the variables (offset, offset2, offset3) from the local level and use 3 global bytes would save space. It went from some 60 bytes to 3, how could it not right? Nope, something with a miss... haha
The image below is a screenshot of when I try to compile for each version of code. One doesn't use global vars and one that trys to. The one without compile with 718 longs in change, and the other using global variables does not compile. Anyone have an idea? I saw the other thread but didn't get an answer or perhaps just missed it thinking it was something else.
The code Im working on is private sensative so sorry I can't upload it to have others to try to compile to make sure there isn't some comma or something I missed. I believe I found a strange thing; I am oddly good at these. haha :thumb:
Thanks for the help,
JD
Comments
I'm not sure if the actual generated code for the methods gets bigger if it has to access object level variables rather than locals which are on the stack.
Without being able to see your code it's going to be tough to diagnose.
You could build your programs with the BST compiler. That can produce a listing of all the generated code and data and in that you can see where everything is put in memory.
Aside: I'm not sure "global" is the right term. The vars are only available to methods of the same object instance. There are no actual globals in Spin.
-Phil
BTW... I have a better pixel driver than the one you're using.
-- http://obex.parallax.com/object/868
@JonnyMac - I will check out the new driver later today, im about go get some sleep. haha
I was just getting clarification before moving in a direction on making things more effecient to add more features; everything works but I knew you all would know immidately so I didn't have to look it up.
there are big differences where you define variables. Especially if you have multiples of one object in your code, say two serial driver or two TVs or two SD-cards.
The simplest to understand are HUB variables in the DAT section. The DAT section can contain a initial value for the variables.
There whatever you define is ONCE in the resulting program image.
If you define a variable in the VAR section it has no predefined value. usually 0 but you can not be sure.
A variable in the VAR section of a (sub)-object occurs per object, so with 2 serial objects they will share their CODE, share the DAT section, but each of them has its own VAR section.
All of this is done at compile time, when the finally image is build.
Now you have local variables, they end up on the stack, and do just exist as long as your PRI/PUB procedure/method is running. Created at the start and released at the end of your call.
The result is that you can use the same memory area multiple times without conflict.
TLDR
Use as much as possible local variables and parameters, avoid global ones in VAR or DAT as long as you do not have a reason to save them there.
Enjoy!
Mike