Re: please confirm something (jdbc)
Thomas Kellerer wrote:
Note that using ByteArrayOutputStream.toByteArray() will create a copy
of its internal buffer so that will double the amount of memory that you
need. That's the reason I wrote my own dynamic byte array (where I can
access the byte array without copying it around)
Using ByteArrayOutputStream.toByteArray() will also guarantee that "the valid
contents of the buffer have been copied into [the resultant array]", and that
the resultant array is the right size. I find these guarantees to be worth
the copy overhead for reasonable-sized objects (under a couple MB, as is
typical for, say, graphic images, one use case for BLOBs).
Given all the memory re-allocation that goes on inside the
ByteArrayOutputStream anyway, I'm not sure that one more allocation is all
that much extra overhead. If you do it right, the internal array of the
ByteArrayOutputStream will immediately become eligible for GC right away
anyway, so the "efficiency" you gain from avoiding that one copy might not be
worth the extra risk and effort of maintaining a custom class.
It depends on how L your BLOB is, naturally. I can see how a large enough
object would require striped processing and other tricks, but like most
optimization this strikes me as one of those "Don't do it 'til you have to,
and don't think you have to until you've measured" scenarios.
--
Lew