Slimelite BBS

Re: Bit Fields - Save Memory

Back to R25C

From Ian James Abbott · 1996-04-10 06:18 · #75287 in R25C

In reply to Bit Fields - Save Memory by Matthew Probert

From: jambo@spuddy.mew.co.uk (Ian James Abbott)

Yo Matthew!
>The variable 'flags' then occupies only four bits in memory, (although
>a complete byte will be assigned for the structure) and yet is
>comprised of four variables that may be accessed like any other
>structure field.

Could be more than a byte, depending on the minimum alignment your
compiler uses for structures.

>A considerable saving in memory over the conventional use of 'int'
>types for flags which would use eight bytes of memory.

Though there is a code space and time penalty compared to accessing a
whole byte. All that bit masking and shifting adds up! Some processors
such as the 68030 have special bit-field access instructions though.

-- 
  * Meeeow! Call Spuddy on +44 1268 515441 for FREE mail & Usenet access. *
--- ifmail v.2.8c
 * Origin: Spud's Public Usenet Domain (2:257/108.12@fidonet)