i found the solution but i don't have a logic explanation:
In a class named myclass extends Thread, I put the follow
public static byte[] utf1= new byte[300000]
.......
InetAddress addr = InetAddress.getByName(IP);
SocketAddress sockaddr = new InetSocketAddress(addr,PORT);
s1 = new Socket();
s1.connect(sockaddr, 1000);
out = new DataOutputStream(s1.getOutputStream());
out.flush();
out.writeBytes(xm1);//xm1 is a little string of 5 lines
out.flush();
int nc1 = number;// is the lenght of the array until i want
send, because array is not full and it have some byte of garbage
out.write(myclass.utf1,0,nc1);// generally nc1 is 200 000
out.flush();
......
s1.close();
out.close();
//to receive i use:
BufferedReader in = null;
in = new BufferedReader(new
InputStreamReader(s1.getInputStream()));
String x="";
int i=0,j=0;
while(i<16){
x = in.readLine();
j=xmlres.indexOf("something");
if(j!=-1){
break;
}
i++;
}
That all. it work fast without garbage collector to send like 1Mbyte.
When i used a string, garbage collector go crazy with the same data,
so my suggest to others is to use an array of byte and send the whole
array to the server. I probe the code on a real device and very old
HTC Magic with API level 3(Android 1.5) and it works fine.
On Sep 23, 2:08 pm, Kumar Bibek <[email protected]> wrote:
> I would suggest that you save the data into a file. and then, send a
> post request with a FileEntity/InputStreamEntity. I have used it with
> HttpClient and it works fine. You would be relieved of all the manual
> work in this case,
>
> -Kumar Bibekhttp://techdroid.kbeanie.com
>
> On Sep 23, 10:44 pm, Paweł Zięba <[email protected]> wrote:
>
> > Do you really need a such big array allocated in memory?
> > Maybe you want to save it to file or database?
> > If so, you don't need to create the huge array.
> > Just try to redirect stream.
>
> > On 23 Wrz, 17:54, TheSeeker <[email protected]> wrote:
>
> > > I have reduced lenght of byte to 250 000 (byte[] array = new
> > > byte[250000] instead of char huge char[] array = new char[900000] )
>
> > > I've been trying sending string instead of character by character. if
> > > string is big (250 000 characters aprox and 250 Kbytes) de Garbage
> > > collector go crazy and the time spend is too much (more than 2 min and
> > > it is funny). Then i do other experiment, split the string in a lot of
> > > little string of lenght of 1024 bytes and 256 bytes. The conclusion is
> > > if string is huge the time is infinite and CG produce the spend of
> > > time, and when the string is small 256bytes GC seem to do not produce
> > > the problem. In the extreme case when i send byte by byte (Log posted
> > > above) is the best case
>
> > > In the original problem is the best case, because GC spent 1,2 seg(150
> > > ms*8) aprox but my chronometer in my hand said 15 seg.
>
> > > This is rare for me because if i send byte by byte i will be sending a
> > > header of TCP/IP about 40bytes. If i send byte by byte i will be
> > > sending 40*(1Mbytes of info) = 40Mbyes and it work better than send
> > > 1Mbyte in a string
>
> > > On Sep 10, 12:53 am, Miguel Morales <[email protected]> wrote:
>
> > > > No, breaking it into two arrays will not help you.
> > > > I haven't done this myself, but I THINK what you'll want to do is use
> > > > a BufferedWriter or something similar. In any case, you'll HAVE to
> > > > buffer your data and send it in chunks. HTTP supports this quite
> > > > well. Take a look at some BufferedWriter tutorials, or perhaps
> > > > someone can suggest a better approach.
>
> > > > On Thu, Sep 9, 2010 at 9:41 PM, TheSeeker <[email protected]>
> > > > wrote:
> > > > > yes, i had a mismach, thanks. But i still have the same problem with
> > > > > time(1 min ) and GC. Create 2 or more array instead of the big one
> > > > > will solve the problem with time?
>
> > > > > On Sep 8, 5:47 pm, Frank Weiss <[email protected]> wrote:
> > > > >> Looks bad, very bad.
>
> > > > >> First, I have no idea why you're allocating 1.8 MB (remember that
> > > > >> Java, and
> > > > >> I suppsoe Dalvik as well, takes 16 bits per char). How come so much?
> > > > >> Second,
> > > > >> of course writing a byte (or is it a char, there's a mismatch there)
> > > > >> is
> > > > >> going to be slower than writing at least a few thousand at a time.
>
> > > > > --
> > > > > 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
>
> > > > --
> > > > ~ Jeremiah:9:23-24
> > > > Android 2D
> > > > MMORPG:http://developingthedream.blogspot.com/,http://diastrofunk.com,http:/...
--
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