Boost logo

Boost :

From: Stefan Arentz (stefan.arentz_at_[hidden])
Date: 2005-08-19 00:53:14


On Aug 19, 2005, at 1:58 AM, Jeremy Maitin-Shepard wrote:

> "Thorsten Ottosen" <nesotto_at_[hidden]> writes:
>
>
>> "Jeremy Maitin-Shepard" <jbms_at_[hidden]> wrote in message
>> news:87acjedijx.fsf_at_jbms.ath.cx...
>>
>>> "Thorsten Ottosen" <nesotto_at_[hidden]> writes:
>>>
>>>>> reason to use std::vector. I do not think the additional safety
>>>>> provided is worth the cost of this overhead.
>>>>>
>>>
>>>
>>>> doesn't the overhead depend on the amount of data sent?
>>>>
>>>
>>> I suppose that is true. If a vector must be passed to the receive
>>> function, then programs using this library will either have to
>>> use an
>>> std::vector for any buffers used for receive, which is annoying for
>>> users that would prefer to use a different data structure for a
>>> buffer,
>>> and has the additional overhead of a dynamically allocated buffer
>>> and
>>> the additional storage std::vecetor requires for the size,
>>> capacity, etc.
>>>
>
>
>> the space required by vector is 3 words. that is not much for many
>> purposes.
>>
>
> Well, I agree it is not a large amount of overhead given certain usage
> patterns. But note that requiring either a vector or a static array
> prevents reading directly into a memory-mapped region. It is also not
> nearly as convenient to directly read a structure or non-char type
> without the memory-range interface.

I've done a lot of work with NIO in the Java world, and what we use
there is a little collection of 'Buffer' objects.

The main advantage is that the buffers are more network oriented and
setup for common tasks that you do in protocol handling.

For example, it is possible to set the byte order for a buffer. You
can simply then push ints on it. Or you could get the first 10 bytes
in a new buffer and then 'compress' the original buffer. That way you
can have sort of a ring buffer where you can take stuff of the
beginning when you have received a full packet.

Always when I use asio, I end up implementing something similar in my
code It would be nice if it were part of the standard asio library.

http://en.wikipedia.org/wiki/Java.nio#NIO_buffers

(Not saying that we should copy this, I'm just saying that it is good
functionality to have in a frmework that does network io)

  S.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk