Shop OBEX P1 Docs P2 Docs Learn Events
Out of memory using Integer.toString — Parallax Forums

Out of memory using Integer.toString

RShirleyRShirley Posts: 12
edited 2005-07-27 16:59 in General Discussion
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()));
····· }··········································

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-07-15 20:43
    The trouble with Integer.ToString() is that it creates a new string.

    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
    ·
  • RShirleyRShirley Posts: 12
    edited 2005-07-27 16:59
    Peter,

    Thanks for all your help, and code. I did find my mistake after some work.

    Thanks, Russell
Sign In or Register to comment.