Segmentation fault (core dumped)

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;
}


##########
classOne.h
##########
1
2
3
4
5
6
7
#include <iostream>
class classOne {
public:
	input();
private:
	bool InArray[100][9];
};


############
classOne.cpp
############
1
2
#include "classOne.h"
input::input(){}


Thanks to everyone who took a look!
Last edited on
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.
Last edited on
I agree with Ispril.
However, you might also look at using a bitset for InArray to reduce your memory usage.
http://www.cplusplus.com/reference/bitset/bitset/

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.

 
  bitset<100> InArray[9];





thank you so much friends!
Topic archived. No new replies allowed.