Out of memory using Integer.toString
Anybody seen any trouble with using "Integer.toString" every time my code uses the method the heap increases till all the memoery is used.
Thanks, Russell
·if (event.buttonDown()) {
······· myLCD.write(Integer.toString(mili.passedMS()));
····· }··········································
Thanks, Russell
·if (event.buttonDown()) {
······· myLCD.write(Integer.toString(mili.passedMS()));
····· }··········································
Comments
Once used, it is no longer used, and since the Javelin has no garbage collection,
you run out of memory quickly.
You can use my class Format.
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/util/text/
In that class there is a function sprintf() that allows you
to print formatted text to a char array.
eg. sprintf(buf,"%5d",value) will print a decimal number, left-justified, up to 5 digits.
You can reuse buf whenever you want. And you are not linited to decimal only.
Also bin, hex, octal, left- or right-justified. Read the description (pdf).
I assume you have a myLCD.write(buf,count) function, else create it
(write count chars from buf to LCD)
regards peter
·
Thanks for all your help, and code. I did find my mistake after some work.
Thanks, Russell