#include <vector>
std::vector<int> v[1000];
int main()
{
return 0;
}
I just used this code with Visual Studio 2019.
Project1.exe!__CheckForDebuggerJustMyCode() Unknown
> Project1.exe!std::exchange<std::_Container_proxy *,std::nullptr_t>(std::_Container_proxy * & _Val, void * && _New_val) Line 599 C++
Project1.exe!std::vector<int,std::allocator<int>>::~vector<int,std::allocator<int>>() Line 676 C++
Project1.exe!`eh vector destructor iterator'(void * ptr, unsigned __int64 size, unsigned __int64 count, void(*)(void *) destructor) C++
Project1.exe!`dynamic atexit destructor for 'v''() C++
ucrtbased.dll!00007ffbdf8e48d7() Unknown
ucrtbased.dll!00007ffbdf8e42e5() Unknown
ucrtbased.dll!00007ffbdf8e441a() Unknown
ucrtbased.dll!00007ffbdf8e4a81() Unknown
ucrtbased.dll!00007ffbdf8e3c51() Unknown
ucrtbased.dll!00007ffbdf8e3afd() Unknown
ucrtbased.dll!00007ffbdf8e3b6a() Unknown
ucrtbased.dll!00007ffbdf8e3de4() Unknown
ucrtbased.dll!00007ffbdf8e4176() Unknown
Project1.exe!__scrt_common_main_seh() Line 297 C++
Project1.exe!__scrt_common_main() Line 331 C++
Project1.exe!mainCRTStartup() Line 17 C++
kernel32.dll!00007ffc168c7034() Unknown
ntdll.dll!00007ffc1829cec1() Unknown
access violation on 0x00007FF6087210D2. Here is a call stack
Why this code crashes? I try to install another version of visual studio (2017), but it still crashes. I've also tried reinstall Window SDK, but it doesn't work.
What can be possible reason, and how to solve it?
Second code sample:
#include <stdio.h>
#include <vector>
int main()
{
printf("before\n");
std::vector<std::vector<int>> v(3000);
printf("after\n");
return 0;
}
The exception changes for every run. One of call stack for above code is:
ConsoleApplication2.exe!std::vector<int,class std::allocator<int> >::_Getal(void) Unknown
ConsoleApplication2.exe!std::vector<int,std::allocator<int>>::vector<int,std::allocator<int>>() Line 446 C++
ConsoleApplication2.exe!std::_Default_allocator_traits<std::allocator<std::vector<int,std::allocator<int>>>>::construct<std::vector<int,std::allocator<int>>>(std::allocator<std::vector<int,std::allocator<int>>> & __formal, std::vector<int,std::allocator<int>> * const _Ptr) Line 695 C++
ConsoleApplication2.exe!std::_Uninitialized_backout_al<std::allocator<std::vector<int,std::allocator<int>>>>::_Emplace_back<>() Line 1509 C++
ConsoleApplication2.exe!std::_Uninitialized_value_construct_n<std::allocator<std::vector<int,std::allocator<int>>>>(std::vector<int,std::allocator<int>> * _First, unsigned __int64 _Count, std::allocator<std::vector<int,std::allocator<int>>> & _Al) Line 1835 C++
ConsoleApplication2.exe!std::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>::_Ufill(std::vector<int,std::allocator<int>> * _Dest, const unsigned __int64 _Count, std::_Value_init_tag __formal) Line 1584 C++
ConsoleApplication2.exe!std::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>::_Construct_n_copies_of_ty<std::_Value_init_tag>(const unsigned __int64 _Count, const std::_Value_init_tag & _Val) Line 462 C++
ConsoleApplication2.exe!std::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>(const unsigned __int64 _Count, const std::allocator<std::vector<int,std::allocator<int>>> & _Al) Line 473 C++
> ConsoleApplication2.exe!main() Line 8 C++
+
this code also crashes
#include <vector>
int main()
{
auto a = new std::vector<int>[3000];
delete[] a;
return 0;
}
#include <string>
int main()
{
auto a = new std::string[3000];
delete[] a;
return 0;
}
So I doubt insufficient memory, however below code works well.
#include <vector>
int main()
{
auto a = new int[10000000];
delete[] a;
return 0;
}
I've try to uninstall all visual studio and Window Kits in visual studio installer, and reinstalled them, however, it still occurs.