D - bit packing
- Pavel Minayev (8/8) Apr 14 2002 Just found out that struct consisting of N bit fields is N bytes long:
- Russ Lewis (9/12) Apr 14 2002 Would probably be clearer if you used
- Walter (6/14) Apr 14 2002 It's an implementation issue whether individual bits get packed or not. ...
- Pavel Minayev (17/21) Apr 14 2002 The
- Walter (6/27) Apr 14 2002 packed?
Just found out that struct consisting of N bit fields is N bytes long: struct bits { bit a, b, c } // bits.length == 3 Why? Since language forbids pointers to bits, why not pack them as tight as it's possible? D does it in bit arrays, but not in structs. I can understand perfomance reasons; then, make some attribute for this. align(0), maybe? struct bits { align(0) bit a, b, c; } // bits.length == 1
Apr 14 2002
Pavel Minayev wrote:I can understand perfomance reasons; then, make some attribute for this. align(0), maybe? struct bits { align(0) bit a, b, c; } // bits.length == 1Would probably be clearer if you used struct bits { align(bit) bit a, b, c; } but otherwise a very good idea. -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Apr 14 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:a9bpjf$134d$1 digitaldaemon.com...Just found out that struct consisting of N bit fields is N bytes long: struct bits { bit a, b, c } // bits.length == 3 Why? Since language forbids pointers to bits, why not pack them as tight as it's possible? D does it in bit arrays, but not in structs. I can understand perfomance reasons; then, make some attribute for this. align(0), maybe? struct bits { align(0) bit a, b, c; } // bits.length == 1It's an implementation issue whether individual bits get packed or not. The main reason for not doing it at the moment is it adds some implementation complexity. As you pointed out, you can always use bit arrays which will pack them regardless.
Apr 14 2002
"Walter" <walter digitalmars.com> wrote in message news:a9clk5$1sfj$1 digitaldaemon.com...It's an implementation issue whether individual bits get packed or not.The Does this statement apply to bit arrays as well, or they are always packed?main reason for not doing it at the moment is it adds some implementation complexity. As you pointed out, you can always use bit arrays which will pack them regardless.Yep, right... but arrays are indexed with integers, and I wanted to have some descriptive names. The code was: class MouseEvent { struct Buttons { bit left, right, middle; } Buttons buttons; ... } I don't really care much if it takes 4 bytes instead of 1... but the latter is preferred, of course.
Apr 14 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:a9co75$2022$1 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote in message news:a9clk5$1sfj$1 digitaldaemon.com...packed? They're always packed.It's an implementation issue whether individual bits get packed or not.The Does this statement apply to bit arrays as well, or they are alwaysimplementationmain reason for not doing it at the moment is it adds someOf course <g>.complexity. As you pointed out, you can always use bit arrays which will pack them regardless.Yep, right... but arrays are indexed with integers, and I wanted to have some descriptive names. The code was: class MouseEvent { struct Buttons { bit left, right, middle; } Buttons buttons; ... } I don't really care much if it takes 4 bytes instead of 1... but the latter is preferred, of course.
Apr 14 2002