Don't worry about the assembler code - that just sets and gets the bits.

Looking in the source for TBits.SetSize we see
  NewMemSize := ((Value + BitsPerInt - 1) div BitsPerInt) * SizeOf(Integer);

where BitsPerInt =   BitsPerInt = SizeOf(Integer) * 8;
Sizeof(Integer) = 4 on my system, so BitsPerInt = 32.

NewMemSize is the number of bytes used in the GetMem function.
For a TBits size of say 10, we get
  NewMemSize = ( (10+32-1) div 32) * 4
  = (41 div 32) * 4
  = 4 bytes

For size = 100 we allocate (131 div 32) * 4 = 16 bytes.

Not bad memory use.  There is also an overhead of 1 Integer for Size and 1
pointer to the Bits array.


Wes Edwards

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Nahum Wild
> Sent: Friday, 15 December 2000 13:06
> To: Multiple recipients of list delphi
> Subject: [DUG]: TBits - array of bits
>
>
> I'm wanting to create a 2d array of bits where the less memory
> used to store
> the array the better.  A boolean array is out of the question as a boolean
> uses up a byte.  So I looked in the D5 help and found the TBits class.  It
> is accessed as a boolean but looking at its source code reveals that its
> coded in assembler.  Which I can't read.  So my question is - does TBits
> store everything at the bit level or at the byte level?
>
> Alternatively does anyone know of a different approach to doing this where
> memory footprint it critical with access speed coming a close second?
>
>
> Cheers,
>
> Nahum Wild
> Game Designer
> Realism Ltd
>
> ESDAO - The wargame of a thousand faces.
> http://www.esdao.net
>
> Download the public beta version now!
>
> ------------------------------------------------------------------
> ---------
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
>

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to