Hi! I've just installed Visual Studio Community 2022 witch C++ package (not everything, just 4GB). Tried the welcome "Hello World" program and it worked then, to try the CPU and RAM profiler, i write this very simple code but it gives me the following error, what is happening??
CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
usingnamespace std;
int main()
{
int TEST[1000000];
for (int i = 0; i < 1000000; i++)
{
cout << "HELLO";
TEST[i] = 0;
}
}
First thank you all, ok i supposed it was this kind of problem but when i was using CodeBlocks i've never occurred in such an error, it was easier indeed, there is a way to use large arrays?
I think i'm not so bad at coding amateur things (i've coded a quite nice raycaster) but have no idea of some technicals: in Codeblocks i use MINGW.. maybe that compiler allows these types of thing? Is it more "elastic"?
Passing a container to a function is a common task. Using a regular array requires passing its size as an additional parameter. Not required with a std::vector:
#include <iostream>
#include <vector>
void arr_func(int[ ], int);
void vec_func(std::vector<int>&);
int main()
{
constexpr size_t SIZE { 100 };
// always initialize an array on creation
int arr[SIZE] { };
arr_func(arr, SIZE);
// a vector is initialized automatically when size created
std::vector<int> vec(SIZE);
vec_func(vec);
}
void arr_func(int arr[ ], int SIZE)
{
// an array passed to a function "forgets" its size,
// so the size has to be passed as an additional parameter
std::cout << "The size of the array is: " << SIZE << '\n';
}
void vec_func(std::vector<int>& vec)
{
// no need to pass the size of a vector, it "remembers"
std::cout << "The size of the vector is: " << vec.size() << '\n';
}
Yes, but in C::B, in one program, i used a single array of 400MB with no problem, i'm curious why i could do that in C::B.
Mm thanks for the advice, i don't know, i'm using C++ sure but i code little games just for fun, on my spare time, so it tooks a while for me to study C++ and honestly don't have time and patiance to learn new things, the one i know, which are pretty simple and straight farword, are more than enough for my projects :/
Are you sure is not fault of the compiler? In C::B i remember an option to NOT follow strictly the C++ rules, if i'm not wrong with some tricks i could even modify array size on the run!
..the real problem to me is that C::B doesn't have a dark mode! But i want to feel free of selling my games and honeslty don't know any other FREE for commercial use IDE (i know VS is for just one developer, my case)..
EDIT:
I will read it with more attention later but it looks more complicate than.. :(
Yyyyes, i would say you are right, but, in my defense, the things i do are altogheder so simple and straight farward that the possibilities of some problem are really low, to be honest in my poorely optimized 5000 lines of the raycasting game i've never occurred is some strange behavior which was not fault of my algorithm or distraction (maybe luck you would say? maybe ahaha!).. just to be clear and let you know me: i don't use pointers, to say that the "bricks" i use are very simple indeed!
the things i do are altogheder [sic] so simple and straight farward [sic] that the possibilities of some problem are really low
That is so wrong. Even simple, short bits of code can be potential bombs waiting to go off. Your code shows that.
PROPERLY using C++ will reduce the errors, not eliminate them. C++ has THOUSANDS of people testing and retesting the C++ libraries. People who are EXPERTS. You act as if you know better than they do.
A good programmer tries to write code that isn't buggy, a sloppy programmer doesn't care.
You should be HAPPY VS 2022 crashed your code. The VS compiler is very strict, unlike the default bundled C::B compiler.
I use VS 2019/2022, MSYS2 for command line editing/compiling and C:B. The C:B IDE was modified to use the MSYS2 compiler. That way I can use C++20 or C++latest when testing code, the bundled compiler with C:B is before C++20, the same as I can with VS or MSYS2.
You should strive to create the best damned code you can, that is portable and C++ standard compliant. To do otherwise is criminal.
I really understand you point of view, but coding is not my job, i don't study coding, is really just a passion that i coltivate time to time so have an array bigger than the one that is imposed by the standards is good to me; my real passion is game logic and algorithms.
I think that all those standards exist to help make a code really safe and stable in every condition, hardware, software, OS version, online applications, enviroment.. that's not my case, i simply don't need all those safe rules, mate, i do some 320x200 retro fps or turnbased rpg in 32bit and 40MB of ram which 35 of them are just for SFML's (for display a window and draw in it) libraries..
Large arrays on the stack? Increase the stack size of the executable to a suitably high value.
from the command line: linker option /STACK:16777216 (for stack size up to 16 MB)
or from the IDE: Configuration Properties -> Linker -> System - Stack Reserve Size