buildhigh.com

The basics...
About buildhigh.com
Archives
About me
Crap I like
Java Tips
Projects...
JonnyChat
Of me...
Name : Jon
Email : click here
Profession : Programmer

October 31, 2005 - Strings is expensive...


One of the things that really jumps up and slaps you across the face and kicks you in the gut about doing any kind of mobile java work is how familiar yet limited the language is when compared to regular J2SE.

One problem I ran into recently was an out of memory exception on what I thought was a fairly standard piece of code. It looked something like this (forgive me for using psuedo java code).

while ((myString.indexOf("<") > -1) && (myString.indexOf(">") > myString.indexOf("<")) { //Do stripping. }

My downfall turned out to be the second indexOf, which referenced an indexOf. On the desktop/server, you really don't give this sort of thing a second thought.

On a phone, you will have to.

Best solution, as far as I could tell, use String.toByteArray(), and loop thru the byte[] and look for my characters and do my stripping within the loop.

It's kinda like the programming style you'd have to use on the C64. But without the comforting click/grunt/grunt/grunt/huuuuum of the 1541.




Go Home...