I have declared an static vector inside a class:
class Algorithm
{
private:
const static std::vector<Algorithm> Cancellations;
}
I initialize the vector outside the class:
const std::vector<Algorithm> Algorithm::Cancellations =
{
Algorithm("F z'"), Algorithm("b"),
Algorithm("b S"), Algorithm("B"),
Algorithm("f z'"), Algorithm("B"),
Algorithm("S b"), Algorithm("B"),
Algorithm("z' f"), Algorithm("B"),
Algorithm("f b"), Algorithm("B F"),
Algorithm("F S"), Algorithm("B z"),
// Many more algorithms
};
Everything works fine, but I have a warning because this vector is too big for the stack, and suggest me that I should move it to the heap, so I change the declaration:
class Algorithm
{
private:
const static std::vector<Algorithm>* Cancellations;
}
And the initialization:
const std::vector<Algorithm>* Algorithm::Cancellations = new std::vector<Algorithm>
{
Algorithm("F z'"), Algorithm("b"),
Algorithm("b S"), Algorithm("B"),
Algorithm("f z'"), Algorithm("B"),
Algorithm("S b"), Algorithm("B"),
Algorithm("z' f"), Algorithm("B"),
Algorithm("f b"), Algorithm("B F"),
Algorithm("F S"), Algorithm("B z"),
// Many more algorithms
};
Everything works fine again, but the warning is still there.
As I read here: When vectors are allocated, do they use memory on the heap or the stack?, if the vector isn't declared static the data should already been stored in the heap in the two cases. Why when I declare a vector static is stored always in the stack? Or I am missundertanding something?
Here is the information about the warning: https://learn.microsoft.com/en-us/cpp/code-quality/c6262?f1url=%3FappId%3DDev16IDEF1%26l%3DES-ES%26k%3Dk(C6262)%26rd%3Dtrue&view=msvc-160
Thank you.