The size of a bitarray??

Discussion in 'C Programming' started by =?ISO-8859-1?Q?S=F8ren_N=F8hr_Christensen?=, Oct 6, 2003.

  1. Hi all!


    I was wondering how much overhead was involved in using a bitarray. In
    other words, how much space does an array of say 32bit use?

    snc
    =?ISO-8859-1?Q?S=F8ren_N=F8hr_Christensen?=, Oct 6, 2003
    #1
    1. Advertising

  2. =?ISO-8859-1?Q?S=F8ren_N=F8hr_Christensen?=

    Mike Wahler Guest

    "Søren Nøhr Christensen" <> wrote in message
    news:blrduu$8nk$...
    > Hi all!
    >
    >
    > I was wondering how much overhead was involved in using a bitarray.


    C does not define anything called a "bitarray".

    >In
    > other words, how much space does an array of say 32bit use?


    The smallest unit of storage in C is a byte, expressed
    with type 'char', 'unsigned char', or 'signed char'.
    These types are required to contain a minimum of eight
    bits, but are allowed to contain more. The number of
    bits in a byte can be determined with the 'CHAR_BIT'
    macro (this value need not be the same for all
    implementations).

    The individual bits of an object cannot be directly
    addressed (but can be examined and modified with the
    bitwise operators, e.g. & and | ).

    Arrays of any type can be created.
    The amount of memory consumed by an array is the product
    of the number of array elements and the array element size,
    in bytes. The size each of the character types is one, by
    definition. The size of any type can be determined using the
    'sizeof' operator.

    char array[100]; /* array consumes 100 bytes, or 100 * CHAR_BIT bits */

    int array[100]; /* array consumes 100 * sizeof(int) bytes, or
    100 * sizeof(int) * CHAR_BIT bits */

    The macro CHAR_BIT is declared by the standard header
    <limits.h>


    Ever considered reading a book about C?

    -Mike
    Mike Wahler, Oct 6, 2003
    #2
    1. Advertising

  3. > I was wondering how much overhead was involved in using a bitarray. In
    > other words, how much space does an array of say 32bit use?


    I don't know. What's a "bitarray"? C doesn't directly support such
    a concept, but there are a number of ways you can implement an array
    of bits.

    If you have some particular implementation in mind, post some (small)
    sample code and we can answer any questions you might have about it.
    If you don't know how to implement an array of bits in C, we can help
    you with that; I suspect there are libraries out there that can do
    what you want. The underlying implementation would most likely involve
    explicit shifting and masking.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
    Keith Thompson, Oct 7, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Madhanmohan S
    Replies:
    5
    Views:
    7,707
    Madhanmohan S
    Sep 3, 2004
  2. Andreas Klemt
    Replies:
    6
    Views:
    10,998
    Peter Theill
    Nov 28, 2004
  3. =?Utf-8?B?QmlkYXJrb3Rh?=

    How to set the DataGrid Row Size to a fixed size.

    =?Utf-8?B?QmlkYXJrb3Rh?=, May 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    812
    =?Utf-8?B?QmlkYXJrb3Rh?=
    May 19, 2005
  4. Neil Zanella
    Replies:
    4
    Views:
    471
    Gianni Mariani
    Oct 9, 2003
  5. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,529
    Michael Jung
    May 25, 2008
Loading...

Share This Page