I am trying to build a lib that interfaces with Python, however Im running into so problems with VS2019. I have found a simple example that shows my problem:
#include <vector>
#include <iostream>
class Foo
{
public:
    std::vector<double> bar;
    void fillBar(Foo& foo)
    {
        int nrElements = 100;
        for (int i = 0; i < nrElements; ++i)
        {
            bar.emplace_back(0.0);
        }
    }
};
int main()
{
    Foo* foo = new Foo();
    std::cout << "Filling bar" << std::endl;
    foo->fillBar(*foo);
    std::cout << "deleting bar" << std::endl;
    delete foo->bar.data();
    std::cout << "The End" << std::endl;
}
This works fine, however if I try to increase nrElements to say 1.000.000 the line delete foo->bar.data() crashes the program. I guess it has something to do with the resizing of the std::vector when the current space is running out. But I would imagine that the data() would still return a pointer I can delete. Especially since when I dereference the pointer it gives the right value for all elements in the vector...
 
     
    