I have a super simple program listed below. When I instantiate my class I get a segmentation fault. When I instantiate the class as a pointer I don't. Why is this? Note the array created is 800mb so not sure why i would get a segmentation fault even if the pointer version might not be actually instantiating the internal structs? (That's my guess on why it is not seg faulting when instantiated as a pointer)
#include <iostream>
#define MAX_NUM 100000000
typedef struct SomeStruct
{
SomeStruct *next;
} SomeStruct;
class MyClass
{
private:
SomeStruct* _some_structs[MAX_NUM];
public:
MyClass(){
std::cout << "size of _some_structs " << sizeof(_some_structs) / 1000000 << "mb";
};
};
int main()
{
MyClass ob = MyClass(); //<-- segmentation fault
// MyClass *ob = new MyClass(); //<-- No prob, prints 800mb
return 0;
}