468,765 Members | 1,526 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

The size of a bitarray??

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

Nov 13 '05 #1
2 4368
"Søren Nøhr Christensen" <sn*@cs.auc.dk> wrote in message
news:bl**********@sunsite.dk...
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
Nov 13 '05 #2
> 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) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Ramzi Abboud | last post: by
2 posts views Thread by Joel Moore | last post: by
43 posts views Thread by Vladimir | last post: by
7 posts views Thread by Eric | last post: by
reply views Thread by James | last post: by
3 posts views Thread by HKannen | last post: by
4 posts views Thread by Rainer Queck | last post: by
7 posts views Thread by Rick Williams | last post: by
2 posts views Thread by semedao | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.