Julien Vermillard wrote:
On Tue, 26 Aug 2008 23:38:40 +0000 (GMT)
Edouard De Oliveira <[EMAIL PROTECTED]> wrote:
- killing IoBuffer
Need some pointers on this discussion about the downsides of it.

Emmanuel can take hours about how much he hates IoBuffer, just meet
him ;)
I don't hate IoBuffer, I just hate that some time and energy has been spent to write something which already exists : ByteBuffer, and for a very bad reason : being able to have an extensible byte buffer.

Why is this a bad idea ? Because :
- ByteBuffers have been written in a way it can't be extended (the constructor is package protected, and can't be called), and this was intended. - ByteBuffers are, err, buffers : they are supposed to _temporary_ hold a piece of data, before it is handled by the receiving part. Extending a buffer is just a non-sense.

Sometime, it's good to stick to the semantic, and use the existing API :

http://en.wiktionary.org/wiki/buffer#Noun

  1. (computing) A portion of memory
     <http://en.wiktionary.org/wiki/memory> set aside to store data
     <http://en.wiktionary.org/wiki/data>, often before it is sent to
     an external device or as it is received from an external device.

The base idea is that you create the buffer, fill it, and send it, or you receive the buffer, read it, and dispose it. As you always know the size of the data you have (either you read it from a socket, and you get a ByteBuffer already allocated, or you create a new one to receive a byte[], and then you already know the byte[] size, so there is no need to resize a ByetBuffer), you don't have to resize a ByteBuffer. If you want to be able to write or read more than one ByteBuffer, NIO already offers the ScatteringByteChannel and GatheringByteChannel for this purpose. No need to reinvent the wheel...

--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org


Reply via email to