Yeah, I'm with @dhayden on this.
I was confused when you said,
I have quite a lot of statements like this in the code, meaning array that are not declared at compile time but rather at run time:
double cov[ind]; |
double cov[ind];
shouldn't compile unless
ind
is defined at compile time to some constant integer type.
If you're attempting to define a dynamic array at run-time with standard C++, you're better off using:
1 2
|
double* cov;
cov = new double[runtimeValue];
| |
Of course that allocates on the heap, which is generally where you want to allocate runtime memory anyway.
As @dhayden said, you're better off using a std::vector. They're most likely implemented as a dynamic array underneath and expose a user-friendly API to work with, plus, they clean themselves up automatically when they're out of scope*
*Unless you have an std::vector<myPointer*>. Then the pointers themselves will be cleaned up, but the memory to which they point will not. For that, You'd need:
std::vector<std::unique_ptr<myPointer>>;
EDIT: But to actually answer your question, if you go with one of these other approaches:
`operator new` actually throws `bad_alloc` if it's not able to get the resources you need, which would be a major indicator if you're using too much of your system's memory.