[clug] [OT] Null-terminated strings: expensive mistake or not

Hugh Fisher hugh.fisher at anu.edu.au
Thu Aug 4 01:07:58 MDT 2011


Robert Edwards wrote:
> 
> I think a similar argument applies to the difference between DIX
> Ethernet frames (as used by IPv4 etc.) which have no length field in
> the Ethernet header and IEEE802.3 frames which do. Manipulating the
> IEEE802.3 frame often requires going back to the header and updating
> the length field. Too bad if the frame is already being put on the
> wire... With DIX Ethernet frames, you just send data until the frame
> ends (as detected in hardware) and the length is implicit
> (cf. \0-terminated). Apparently makes network stacks heaps easier to
> write.

My understanding is that network people prefer length then data
most of the time, and much more so back in the days when 64K
was a lot of RAM.

If you're reading from a socket/stream, length then data lets
you allocate the buffer you need and copy into it. With C style
termination you have to allocate a maximum sized buffer and
copy into it, or keep reallocating the buffer on the fly as
more data arrives.

Even on writes, it's easier if you know how many frames you
need ahead of time.

	cheers,
	Hugh Fisher



More information about the linux mailing list