[Solved] std::vector destructor gives error


Since you said you use dll_export, the cause of corruption can be one or more of the following:

  • The application and DLL were not compiled with the same compiler options in terms of code generation.

  • The application and DLL are using different heaps at runtime.

For the first item, you must make sure that the compiler options such as structure packing, and any other option that will change the class’s internals in some way, are the same. But even more basic, the app and DLL must be compiled with the same version of the compiler.

For the second item, you must make sure that the application and DLL use the same heap. To do this, both the DLL and app must use the DLL version of the runtime library.

When you have a class that handles dynamically allocated memory such as std::vector passing and using these class across module boundaries become error prone. Note that the problem is not std::vector, as any class, even one that you would have written, would have the same issue if the class uses the heap.

1

solved std::vector destructor gives error