Out of Memory
TE44
Posts: 42
Working with a loop - I wanted to print a value - I noticed that if I do the following I get no error
import stamp.core.*;
public class MEM {
· static int val ;
public static void main(){
do{
val = val +1;
System.out.println(val);
}while(true);
}
}
How ever if I do the following - I get a memory error after a count of approx 2000
import stamp.core.*;
public class MEM {
· static int val ;
public static void main(){
do{
val = val +1;
System.out.println(String.valueOf(val));
}while(true);
}
}
Can I clear a buffer or something ?
I have a routine where by I want to send an int·out·via the Uart·- I can not
use the following
txUart.sendString(val);
because val is an integer so I tried the following -
txUart.sendString(String.valueOf(val));
which successfully sent the values but I get out of memory errors after about 2000
I wrote the above routine 'MEM'·to see where my problem was and it was with (String.valueOf(val));
is there a way around this?
Any help greatly appreciated.....
·
import stamp.core.*;
public class MEM {
· static int val ;
public static void main(){
do{
val = val +1;
System.out.println(val);
}while(true);
}
}
How ever if I do the following - I get a memory error after a count of approx 2000
import stamp.core.*;
public class MEM {
· static int val ;
public static void main(){
do{
val = val +1;
System.out.println(String.valueOf(val));
}while(true);
}
}
Can I clear a buffer or something ?
I have a routine where by I want to send an int·out·via the Uart·- I can not
use the following
txUart.sendString(val);
because val is an integer so I tried the following -
txUart.sendString(String.valueOf(val));
which successfully sent the values but I get out of memory errors after about 2000
I wrote the above routine 'MEM'·to see where my problem was and it was with (String.valueOf(val));
is there a way around this?
Any help greatly appreciated.....
·
Comments
or is it simply rubbish code ??
used once. You can of course use StringBuffer and then reuse that.
The easiest way is to use the Format class.
char[noparse]/noparse asciiNum = new char[noparse][[/noparse]7]; //holds ascii representation: sign,5decimals,closing null
int value = 123;
Format.sprintf(asciiNum,"%d",value); //convert int to ascii
tx.sendString(asciiNum); //transmit all characters·exclusive the closing null
You should use my adapted Uart class.
Rename the current Uart.java to Uart_org.java
then copy my Uart.java from
http://tech.groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/
into folder .../lib/stamp/core
You will find the Format class here:
http://tech.groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/util/text/
copy Format.java into folder .../lib/stamp/util/text
Format allows you to print binary,octal,decimal,hexadecimal and unsigned values.
regards peter
Thats great - both worked - also tried StringBuffer with a
buffer.clear();
and it works fine !
You the man !