My program compiles fine but for some reason i get this error "Segmentation fault (core dumped)" when I try to run it. When I reduce the number of objects from 10,000 to 1000 it works fine so am i just using more system resources than my computer has available? It really seems like my pc should have the capacity to create more than 10,000 instances of a class but maybe thats wrong. Any idea whats going on here? Any idea how to fix it? I eliminated as many variables as possible from the program while still managing to get the error in order to make it easier on you guys.
########
main.cpp
########
1 2 3 4 5
#include "classOne.h"
int main() {
classOne classOneObj[10000];
return 0;
}
Well, the issue isn't that it is too large for your computer, but too large for your computer's stack. You have to create a dynamic array of that many values so that it is instead allocated to the heap, where it should work. It's not so much a segmentation fault as it is a stack overflow.
bitsets provide optimum storage for boolean values.
A bool is usually implemented by that compiler as a char.
Therefore each InArray takes 900 bytes.
Assuming a 32 bit word, a bitset<100> would take 16 bytes.
An array of 9 bitsets would take 144 bytes.
This would reduce the overall storage from 9MB to 1.44MB.