vector<economy> econVector; // create a vector of type economy
Off-topic chat about stack size considerations:
Looking at your code, it seems that each economy object contains 45000 double objects (ignoring the firmType and BankType objects). If each of those is four bytes, that's around 180000 bytes. You're trying to make 400 of these, so you're trying to allocate around 72000000 bytes, or roughly 72 megabytes.
Typical default stack size on a consumer Windows OS machine is one megabyte, if I recall correctly.
Yes. When I make T = 30 for example, program properly works. But when I make it 200 or more it gives stack overflow. And sometimes it also says:
"exception: std::bad_alloc at memory location 0x001ff658"
What is firmType and bankType? Are they structs as well, enums, ints, some object?
If double is 8 bytes on your system, not including firmType/bankType or padding, then your looking at 144MB. This is not much, but without knowing, the size of those struct and or how much ram your system has it's hard to know. I'm able to allocate 1.4GB worth of memory using the code you've posted (Making up my own firmType/bankType) by declaring arrays of 9 int for each of those. I don't crash until I create 4500 size economy. I'm running on Windows server 2003 with 16GB of Ram.
this is not preferred and is slower than:
And this is an alternate method that may be more efficent: std::for_each(vecEcon.begin(),vecEcon.end(),SomeMethod);
'phd_10101516.exe': Loaded 'C:\Users\ILKER\Documents\Visual Studio 2010\Projects\phd_10101516\Debug\phd_10101516.exe', Symbols loaded.
'phd_10101516.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'phd_10101516.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'phd_10101516.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'phd_10101516.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'phd_10101516.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
First-chance exception at 0x753cc41f in phd_10101516.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x004bfa8c..
Unhandled exception at 0x753cc41f in phd_10101516.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x004bfa8c..
The program ' phd_10101516.exe: Native' has exited with code -529697949 (0xe06d7363).