$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-10-18 06:21:25
Beman Dawes wrote:
> "Christopher Kohlhoff" <chris_at_[hidden]> wrote in message
> news:20051017052938.33920.qmail_at_web32604.mail.mud.yahoo.com...
>> Hmm, I'm not sure. Here are the current uses of void* and their
>> rationales:
>>
>> * buffer() and buffers() - so that arbitrary application data
>> structures can be sent without an additional buffer copy.
>
> Where did this idea come from that the only way to avoid an
> additional copy is to use a void *?
>
> Think about the iterator interfaces to Standard Library algorithms.
> They traffic nicely in pointers, yet not a buffer copy or void * to
> be seen.
But the algorithms operate on typed data, and asio/sockets operate on
untyped data. They gain nothing from an iterator interface, because they
simply can't provide type safety. When you send a type T over the wire, what
comes out at the other end is an untyped sequence of bytes that may have
been a T on the source machine, but is not necessarily a T on the target; so
even if the target could somehow deduce the type - and it cannot - it
wouldn't be very useful to cast the byte sequence to an invalid T.
It's better to not provide an illusion of type safety when there is none;
the buffer is a raw sequence of bytes and (void*, size_t), (unsigned char*,
size_t) and (unsigned char*, unsigned char*) are its natural
representations. It really is of type "raw sequence of bytes", and using
another type to describe it decreases type safety rather than increasing it.