This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
How to avoid memory reallocation in UDP receive
- From: "P.O. Gaillard" <pierre-olivier dot gaillard at fr dot thalesgroup dot com>
- To: "java at gcc dot gnu dot org" <java at gcc dot gnu dot org>, jean-marie at dautelle dot com
- Date: Tue, 09 May 2006 13:42:20 +0200
- Subject: How to avoid memory reallocation in UDP receive
- Reply-to: pierre-olivier dot gaillard at fr dot thalesgroup dot com
Hello,
I am looking at the gnu::java::net::PlainDatagramSocketImpl::receive code
because it allocates memory on the heap when it should not need to (the Sun JDK
does not seem to allocate on the heap with the same program).
The reason for the allocation seems to be that the IP address is stored as an
array and since the IP address may be 4 or 16 byte long (IPv6) the code just
reallocates the array to store the IP address every time a new message is received.
I would like to avoid that and do the following :
1) check that an IP address with an byte array of the right size is available
2) if not execute the current code (i.e. allocate an new InetAddress instance
and fill it with the data)
3) if there is an InetAddress instance that can be reused, update the byte array.
It seems that I would need to modify InetAddress.java (add a protected/private
setAddress method) and PlainDatagramSocketImpl (use the new method in
InetAddress to update the address instead of allocating a new one).
Of course, this might cause unwanted side-effects for programs that kept a
reference on the address found in the datagram instead of making a copy.
So, I would like guidance from the GCJ folks :
1) does the change seem reasonable ?
2) could I submit a patch and to whom ?
If such a change seems too special for java.net package, would you know a small
networking library that is meant to work without GC ?
thanks for your attention and help,
P.O. Gaillard