简体   繁体   English

如何有效地表示非常大的位数组?

[英]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. 由于布尔值实际上占用1个字节的空间 ,因此bool[]并不是表示位数组的最节省空间的方法。 Sometimes integers and longs are used as a more efficient bit array, but a long can only hold 64 bits. 有时,整数和long用作更有效的位数组,但是long只能容纳64位。 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, ie the only functions I need: 我需要对该数组进行的所有操作是设置/清除各个位,并检查某些位是1还是0,即我唯一需要的功能:

void Set(int index, bool value);
bool Get(int index);

我认为您需要的是BitArray

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM