From mboxrd@z Thu Jan 1 00:00:00 1970 Message-Id: <200412142248.iBEMmJJ20061@augusta.math.psu.edu> To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Subject: Re: [9fans] (no subject) In-Reply-To: Your message of "Tue, 14 Dec 2004 22:36:38 GMT." <9E3DCD40-4E20-11D9-901F-00112430C042@gmail.com> Date: Tue, 14 Dec 2004 17:48:19 -0500 From: Dan Cross Topicbox-Message-UUID: 161da87a-eace-11e9-9e20-41e7f4b1d025 jim writes: > If you'll pardon a humble mortal's ignorance, what's so bad about it? > Well, re-phrase that - how else to do accurate bit-packed structs like > for tcp/ip headers? As I read this thread, 'packed' allows just that; > it tells the compiler not to mess with how you've packed a given > struct. In which case, it seems pretty useful to me - I'd love to know > how real coders do tcp/ip headers :-S. How do you do `accurate bit-packed structs'? You don't. In the specific case you mention, you write code to marshal it into and demarshal it from a byte stream. The argument(s) for packed structus is that it makes (1) in-core representations more space-efficient (who cares, honestly, about saving a few bytes here? Maybe for some embedded environments it makes sense, but in general, I'd say don't bother), (2) makes the program `cleaner' by not having to write explicit marshalling code. I think if that code is written properly (ie, isolated somewhere) it's not significantly cleaner than the alternative, unpacked record, and (3) I'm sure that the false-idol of efficiency is worshipped somewhere with the cost of marshalling, both in terms of space and time. This last I'd say is a pure straw-man: if you have to trap into the kernel with every memory access, you're really not doing yourself any good in terms of time, and usually you're going to assemble the packet in fragments and copy it all somewhere at the last second anyway. You could do the marshalling then and avoid the whole multiple-trap thing, with no additional cost in memory usage. Basically, this is one of those ideas where someone said, ``hey, wouldn't it be cool if...'' and fixed a problem with the design of their code by changing the language. - Dan C.