I am writing a program in C++ for a embedded platform STM32. I used to use normal arrays but for the first time I am using vectors in it. So far it runs well in the majority of the cases. However in a very few cases I got the error stated in the title eventhough it shouldn't. Would appreciate some help as I run out of ideas.
My situation
The vectors are like this
struct Boundary{
vector<unsigned short> x; //The x coordinates
vector<unsigned short> y; //The y coordinates
};
Everytime I use these vectors I clear them with
boundary0.x.clear();
boundary0.y.clear();
I add elements with the normal push_back
The strange part
Sometimes, the program finishes with the "Operator new out of memory" when adding elements to the vector.
"!Ah, you run out of memory!"- you would say, but that is the strange part. The vector so far has only 275 elements which being short gives 550 bytes.
But this very same program has handled the same vector with many more elements (500 or more) without problem.
Somehow, you previously leaked out memory!- can be said, and I suspect that. Perhaps I used this before and failed to clean it up (although I cleaned it as I stated) but this error appears even when I disconnect and connect the processor wiping out any previous used memory.
I am at lost why this could be happening. Any help or comment or advice greatly appreciated.