Out of memory ?
Mark Bramwell
Posts: 56
I am programming away successfully and suddenly a simple case statement causes odd things to happen. I comment out the case statement and it all works again. I add 1 line of code and it breaks again. What I do notice is a bit of corruption occurring in the upper left corner of the screen.
I am running with both the TV and GRAPHICS objects. I noticed that one of them has the bitmap_base=$2000, display_base = $5000
Any chance that memory range is being overwritten because the program+vars are now hitting the bottom of that range?
This is what the Object Info screen says:
RAM Usage:
Program: 1,753 longs
Var: 246 longs
Stack/free: 6,189 longs
If I add back the case statement, the program jumps to 1,782 longs.
Am I screwed at this point? Am I out of usable memory? I want to display graphics, should I be using something else that is less memory intensive?
I am running with both the TV and GRAPHICS objects. I noticed that one of them has the bitmap_base=$2000, display_base = $5000
Any chance that memory range is being overwritten because the program+vars are now hitting the bottom of that range?
This is what the Object Info screen says:
RAM Usage:
Program: 1,753 longs
Var: 246 longs
Stack/free: 6,189 longs
If I add back the case statement, the program jumps to 1,782 longs.
Am I screwed at this point? Am I out of usable memory? I want to display graphics, should I be using something else that is less memory intensive?
Comments
The off-screen buffer starts at 8K taking 12k, then follows the on-screen buffer of the same length to End -Of- RAM.
8K for your code and variables mean 2048 longs, You use 1782 + 246 = 2028.
20 bytes = 5 words is by no means enough for the stack, so your own analysis is quite correct.
First idea: Do you really need the double buffering? It is necessary for smooth animation, but a single buffer can be acceptable for other applications. It is easy to change...
Second idea: What is your tile-setting? Do you really need 12 kB?
Third idea: Can you possibly live with 2 color mode?
Fourth idea: When you still use all the stuff to setup the video driver for multiple-object support, you can save a hindred bytes or so by using the DAT variables directly rather then copying them into your object space... This is not much, but you can carry on at least...
Post Edited (deSilva) : 9/8/2007 10:56:04 PM GMT
Note that you have now reduced the screen height to 176 rather than 192. But everthing should sort itself out automatically...
I doubt that I need double buffering. If I can get the same resolution (or better) with single buffering, I can carefully code around it if I suddenly get lots of ram to use. I read that double buffering gets rid of flickering. How bad is the single? Is there a demo program that uses single buffering so I can view it? Very little of the screen changes from second to second. I know the hydra has multiple video drivers but it was not clear to me if they were TV drivers and if they were single/double.
My app is mostly text. I would use "text mode" if I could get large and small fonts. I added a Vu meter graphic because I could. I would lose it if the text mode had more flexibility in the fonts.
I am using the 2 objects that are on the site (TV + Graphics). Do you have a better suggestion? I am only about half through the applet and was surprised to hit a ceiling already.
The applet is meant to control an Icom PCR shortwave receiver using a Sony remote control and viewed on a TV screen. It will actually be connected to a slingbox and will allow me to use it anywhere. The Icom PCR has no buttons or controls. It is meant to be connected to a PC via the serial port and controlled that way. It is my hope that I can write something to send the control bytes using the propeller and remotely view/control it via the slingbox.
What I have working is a decent screen GUI with the IR_KIT decoding the Sony remote. I have not added any of the RS232 stuff yet. That is why I feel I am only half way there.
Regarding the tiles.... I do not completely understand them. The sample code generates 64 colors[noparse]/noparse yet the screen only uses about 15 or less of them. If I set a colors[noparse][[/noparse]x] = xxxxxxx, it affects the entire line and I only have about 15 lines for text (15 might not be the exact number, it could be less). I have attached the spin file in case you are interested in what I was trying to do. It is my 1st spin program, I am sure there are better ways to do some things, I am still learning.
O.k. - there it is
That was naughty of you!! Why do you use 16 and 12 rather than "x_tiles" and "y_tiles"???
If you change that, it should look much better!!
It makes things a little bit more complicated that you are just learning these things....
The double buffering is a feature of GRAPHICS and has nothing to do with the videodriver TV. GRAPHICS just uses the memory that is displayed by TV. GRAPHICS uses four "symbolic" colors, but has no understanding of what they mean. You can modify these to real colors with respect to the screen position where the occur by the tiole logic.... O.k. it is NOT simpel...
Coming to double buffering...
This however is the most simple part of all!
At the end of your main loop there is something like
Delete this!
Now tell GRAPHICS to write directly into the display buffer
Now bitmap base at $2000 is no longer used and you should have additional 12KB
You get 12 kByte more RAM for Spin (3000 Longs), but you get also strong flickering with your momentary code.
Modify your code so, that you only redraw the display, if something changes. Perhaps you can also only redraw the portion of the screen, that has changed.
Andy
Edit: OK deSilva was faster!
Post Edited (Ariba) : 9/9/2007 1:27:39 AM GMT
Holy Flicker! The screen is flicking all over the place. My program was clearing and redrawing everything between frames. The double-buffer made it look solid.
To stop the flickering, I added a few flags to redraw only those portions that have changed. Even then, I write the old values with the background-color (causes it to disappear without redrawing the entire box of info) and then I write the new value in the proper color.
Everything is now back to the same visual flicker-free video but I now have lots of ram again.
Thanks for the help!
One other question... Is the rom font constant pitch? I mean, does a space " " take the same number of pixels wide as a "z"?
I think it is a variable pitch font because if I write "---" and then write in another color " - ", I get overlapping color where it should be clean.
Now I am being hit with the signed 32-bit integer problem. I need to display upto 4-billion (with formatting) which is easy with an unsigned 32-bit int but not if it is signed.
oh well, I'll make my own lib that can handle large numbers with formatting. It slows me down a few days but I can get past it. I'll probably do it as an array of byte and perform the carrys on the addition/subtraction. That will allow me to have numbers of any size with simple add/sub capability.
Just an idea. Mightor is quite advanced with math in assembly language now Maybe you can order a package for "multi precision arithmetic" from him...
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
I would like to display some graphics, with small pre-defined bitmaps to mix with the text as icons. Maybe this is a little OT, but does anyone know of a good way to 64-word align an area of memory besides padding and pointer rounding? Seems redundant to define a bitmap and then have to copy it to another area before I use it.
Ken
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
The reason for using 10 bit-addresses (=64 byte align, not 64 word align) is that this has the least redundancy. There is absolutely no reason why you should not use long-numbers (= 4 Byte align) That leaves you 2 bits for color mapping when you want to stay with the word tiles.
Everything is possible when you start to change the drivers!!
I agree, re-writing the driver would allow trading some of my color palette for finer resolution in memory, but I'm not about to re-write the driver only to save 15 longs of memory unless I really need 15 more longs! My time is short and I have bigger fish to fry.
I guess I was wondering if there was a simpler, more elegant way to align blocks of memory with greater granularity than a long. This might be useful for other things as well.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
There is simply no "ALIGN" directive, forcing a DAT section to start at - say - a multiple of 64. A DAT section always starts long aligned....
how?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My computer, http://forums.parallax.com/showthread.php?p=630466
tv.spin has the tv_status variable that indicates in which state the driver is.
Draw only, if tv_status is 1 and wait if tv_status is 2.
repeat until tv_status == 1
remove old graphic
draw new graphic
I still get the flicker on that particular object. Not a big deal. Perhaps spin is not fast enough to execute the draw commands before the sync is done.
This is how I remove the old text. I change the text to the background color, overwrite it with the same data which causes it to disappear and then write the new text.
I am not sure if this is the fastest way to remove text from a portion of the screen but it seems to work (with some flicker).
gr.textmode(2,3,6,5)
gr.colorwidth(1,1) ' background color
' remove old text
gr.text(0,55,num.ToStr(PCR_Freq[noparse][[/noparse]PCR_VFO],num#DSDEC14))
gr.colorwidth(2,1) ' new color
' draw current text
gr.text(0,55,num.ToStr(PCR_Freq[noparse][[/noparse]PCR_VFO],num#DSDEC14))
gr.finish
I don't know how much stuff you have on your screen, but you might also consider clearing and re-drawing the entire screen every update. How often are you updating the screen? Perhaps you can divide your update routine over several frames.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The more I know, the more I know I don't know.· Is this what they call Wisdom?
So basically, you don't need any special library for 32-bit unsigned values, unless you need more than just add and subtract. The only change you'd need to make is in the code that converts a long to the human-readable string of digits that you show on screen, to correctly show the unsigned "interpretation" of those 32 bits. It might be a bit tricky to do this conversion on the propeller, but it should be possible.
If you need multiplication and division, or just like to know more about signed/unsigned values, you might check here: http://en.wikipedia.org/wiki/Two's_complement
Post Edited (_Mark) : 9/12/2007 2:11:04 AM GMT
I have a variable called PCR_Freq[noparse][[/noparse]PCR_VFO] that contains the newly calculated number to display (13 character string)
DisplayedFreq contains what is on the screen.
The following routine looks for differences and wipes that small portion of the screen and paints the new number (that single digit).
No more flicker!
I might have the unsigned part sorted out due to some help from a parallax guy (beta object)
It would be nice for some addition 'types' to be added to spin.