Nickolouse
Nickolouse

Reputation: 301

bool array vs bit array in C

I am in need of implementing an efficient bit array in C. From what I have seen C does not support this so you can use an array of integers (according to one site I looked at) and then use a shift to access individual bits. Would simply declaring a bool array be the same thing or is this less memory efficient?

Upvotes: 6

Views: 2463

Answers (1)

Carl Norum
Carl Norum

Reputation: 225202

Yes, a simple _Bool array require more storage than an array of integers combined with some bit-shifting. The _Bool array stores one bit of data in a sizeof(_Bool) space (normally a single byte). The integer array can store many more bits per byte (minimum 8).

Upvotes: 6

Related Questions