www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - bit array

reply Orgoton <orgoton mindless.com> writes:
When I declare

bit flags[120];

How much memory does this consure? 120 Bytes or 120 bits (packing).
It would be a pain to make something like "long flags1, flags2..." and "if
(flags1 & FLAGMASK) ..." to conserve memory.
Feb 07 2007
parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Orgoton wrote:
 When I declare
 
 bit flags[120];
 
 How much memory does this consure? 120 Bytes or 120 bits (packing).
 It would be a pain to make something like "long flags1, flags2..." and "if
(flags1 & FLAGMASK) ..." to conserve memory.
It used to only consume 120 bits, when 'bit' was still a basic type. There were some issues with that though, so now 'bit' is just a backwards-compatibility alias to 'bool'. Since 'bool' is a 1-byte type (typically) that means it'll consume 120 bytes.
Feb 07 2007
parent reply Tomas Lindquist Olsen <tomas famolsen.dk> writes:
Frits van Bommel wrote:

 Orgoton wrote:
 When I declare
 
 bit flags[120];
 
 How much memory does this consure? 120 Bytes or 120 bits (packing).
 It would be a pain to make something like "long flags1, flags2..." and
 "if (flags1 & FLAGMASK) ..." to conserve memory.
It used to only consume 120 bits, when 'bit' was still a basic type. There were some issues with that though, so now 'bit' is just a backwards-compatibility alias to 'bool'. Since 'bool' is a 1-byte type (typically) that means it'll consume 120 bytes.
As a note to this you can use std.BitArray in phobos to have a true bit array. Not sure what the Tango equivalent is. http://digitalmars.com/d/phobos/std_bitarray.html
Feb 07 2007
parent Sean Kelly <sean f4.ca> writes:
Tomas Lindquist Olsen wrote:
 Frits van Bommel wrote:
 
 Orgoton wrote:
 When I declare

 bit flags[120];

 How much memory does this consure? 120 Bytes or 120 bits (packing).
 It would be a pain to make something like "long flags1, flags2..." and
 "if (flags1 & FLAGMASK) ..." to conserve memory.
It used to only consume 120 bits, when 'bit' was still a basic type. There were some issues with that though, so now 'bit' is just a backwards-compatibility alias to 'bool'. Since 'bool' is a 1-byte type (typically) that means it'll consume 120 bytes.
As a note to this you can use std.BitArray in phobos to have a true bit array. Not sure what the Tango equivalent is.
tango.core.BitArray. The implementation is essentially the same. Sean
Feb 07 2007