Here is the code for the serialize(Serializable) method:

    public static byte[] serialize(Serializable obj) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        serialize(obj, baos);
        return baos.toByteArray();
    }

This can be sped up a significant amount just by using a different constructor for the
ByteArrayInputStream instance, passing in a number higher than 32, so it constructs a 
bigger
initial buffer than it otherwise would.  Bumping up the initial buffer size to 128 
worked about as
well as bumping it up to 512 on my machine.

This alone resulted in an overall 6% speed increase for the clone(Serializable) method 
on my
machine.

For the methods serialize(Serializable, OutputStream) and deserialize(InputStream) it 
may be
desirable to wrap the passed streams in buffered streams.  Serialization to/from 
streams is
typically done for persistence, passing objects between JVMs, etc. and it's not hard 
to imagine
someone passing in unbuffered streams in these situations...

Jeff

__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to