without wishing to bang on about this --

every time you write string1 += string2, the VM will instantiate a 
StringBuffer with string1, append string2 to it, and then assign the 
buffer's toString() back to string1. that's at least 2 instantiations 
per iteration, and instantiations are *expensive*.

in your (admittedly maximum) example of 200 bytes, you're doing 400 
instantiations. if the phone's network connection is slow, then it 
might not comprise a big percentage of elapsed clock time, but if not 
you might find that kind of cost is noticeable. also, the difference 
between the fast case and the slow case would buy you some extra 
thread capacity on a server.

i cache remote resources all the time, so i have a utility class 
which has the following handy methods - (1) open a network connection 
and return a stream reference to its contents (2) copy an input 
stream to an output stream, optionally in text or binary mode, using 
configurable size buffers and (3) combine (1) and (2) to enable 
clients to cache remote resources with one line of code.

however big the remote resource is, it always gets read the same way. 
i never have to worry about whether to do it right, because my lower 
layers always do :-)

hth




>Jason, you're right about the efficiency of appending to a string. I
>use it for short messages only. I use an input stream to create a DOM
>document, which probably isn't efficient either. But then, if all you
>get is 200 bytes at most, who cares.
>
>Christine



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to