
On Fri, 2005-04-22 at 14:23 +0300, Peter Dimov wrote:
Iain Hanson wrote:
On Fri, 2005-04-22 at 12:42 +0300, Peter Dimov wrote:
[ snip ]
This would give a significant performance hit as there will now be two copies of the data. The 1st from kennel space to the library and the second in the callback from the library to the user.
Sometimes, yes, but not always. You don't have to make a copy in the callback, and for small packets and low bandwidth, the extra copy may not be significant. Also note the "by default" in the above. I am not against manual buffer management, just against the absence of automatic buffer management.
I really don't see this as workable in the general case. The library has to guess the size of the read buffer. It would also prevent reading a complete record on a stream by reading a header up to the length field and then making a 2nd read call for that length with the correct size buffer. It would also add dynamic memory allocation to the library and be a source of runtime errors as a result a user not copying the buffer and trying to use it after its lifetime expired. I know we can't always protect users from themselves but we do try to not make it easy for them to make mistakes. /ikh