简体   繁体   中英

A very long boolean array/std::bitset

For some C++ code, my logic requires a boolean array containing 4*10^10 indices. I am using the STL container std::bitset . But its implementation as template < size_t N > class bitset; restricts the number of bits to the upper limit of the size_t (unsigned integral type) data type, which is 2^32-1 (or 2^64-1) { Can someone confirm this as well }.

I thought of a workaround for this issue by creating an array of bitset , as in bitset<100000000> checkSum[400] ;

Is this legal? I am getting the following compilation error (test.cpp is my C++ file)

/tmp/cc0gR0c6.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x35f): relocation truncated to fit: R_X86_64_32 against `.bss'
test.cpp:(.text+0x373): relocation truncated to fit: R_X86_64_32 against `.bss'
collect2: ld returned 1 exit status

Can this somehow be fixed or is there a better workaround?

我认为您应该使用向量而不是数组,就像:

vector<bitset<1000000> > checkSum;

size_t is either 32 or 64 bits, depending whether you're compiling 32 or 64 bit code. It looks like you can simply compile for a 64 bit target and solve this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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