Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to represent a very large bit array efficiently?

Since a boolean actually takes 1 byte of space, a bool[] isn't the most space-efficient way to represent a bit array. Sometimes integers and longs are used as a more efficient bit array, but a long can only hold 64 bits. Is there a more space-efficient way to store arrays of tens of millions bits in limited memory?

All I need to do with this array is to set/clear individual bits and to check whether some bits is 1 or 0, i.e. the only functions I need:

void Set(int index, bool value);
bool Get(int index);
like image 881
Louis Rhys Avatar asked Dec 21 '22 10:12

Louis Rhys


1 Answers

I think what you need is BitArray class

like image 73
I4V Avatar answered Dec 22 '22 23:12

I4V