My C++ program has a very large const array, which should be allocated on the heap, but for some reason it's crashing my stack. It goes something like this:
Foo.h
#pragma once
#include <vector>
struct Data
{
short id;
std::vector<short> points;
Data(short i, std::vector<short> p) : id(i), points(p) {}
}
class Foo
{
private:
short id;
std::vector<Data> data;
public:
Foo(short i, std::vector<data> d) : id(i), data(d) {}
};
ARRAY.h
#pragma once
#include "Foo.h"
const int ARRAY_LENGTH = 1058;
static const Foo *ARRAY = new Foo[ARRAY_LENGTH]
{
Learnset(1, std::vector<Data>({
Data(1, std::vector<short>({151, 489, 435, 65, 282, 355, 92})),
Data(8, std::vector<short>({286})),
Data(19, std::vector<short>({595})),
Data(26, std::vector<short>({417, 201})),
[...]
})),
[...]
}
This array basically serves as a database for the program. I know it's this array causing the overflow because if I comment out most of it, the program runs just fine.
Even stranger is that, when I check using sizeof, the program reports that the array is 4 bytes long, just like I would expect it to be, so I think that the program might be trying to build the array on the stack before moving it to the heap, and I'm not sure if my use of vectors is responsible. I have no idea how to correct it.