Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bool array vs bit array in C

Tags:

c

linux

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?

like image 570
Nickolouse Avatar asked Nov 17 '14 22:11

Nickolouse


1 Answers

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).

like image 103
Carl Norum Avatar answered Sep 29 '22 18:09

Carl Norum