[jbosscache-dev] Re: Any reason not to use ExposedByteArrayOutputStream instead of ByteArrayOutputStream ?

Bela Ban bela at jboss.com
Fri Jul 4 07:32:37 EDT 2008



Manik Surtani wrote:
> But that would involve JGroups code calling Buffer.copy() again, which 
> is the same as using a normal BAOS.  Just that it happens a bit later 
> in the chain of events.

No: the byte[] buffer with offset and length are passed down to the TCP 
or datagram socket and *NOT* copied at all !


> This should have far-reaching consequences as I'm not aware of anyone 
> else but JBossCache to use Marshaller. Or maybe, to be on the safe 
> side, I could create a Marshaller2 so existing code doesn't break 
> (extending Marshaller)... 
> http://jira.jboss.com/jira/browse/JGRP-796That should
>
> I wasn't talking about reusing stream instances, I was referring to 
> the same problem you have above with JGroups is going to be 
> encountered with every cache loader impl in that the byte[] retrieved 
> may be larger than necessary and contain uninitialized values.

So JBC has to switch to a Buffer-like implementation too. At least where 
it is important. I suggest do it immediately wherever code can be 
changed (e.g. internal code) and defer it to later in cases where 
external code might rely on it, in order not to break anything.

We need to reduce copying wherever possible !

-- 
Bela Ban
Lead JGroups / Clustering Team
JBoss - a division of Red Hat



More information about the jbosscache-dev mailing list