Answer the question
In order to leave comments, you need to log in
Is there a way in c++ to allocate memory for all variables?
Good day,
Is there a way in c++ to allocate memory for all variables. For example, this story:
I am writing a program that takes data from the clipboard and saves only English letters there. Wrote under Dev c++ portable, in vmware thinstall container. It assembled and when I run it on the button in the IDE it works, however, when I launch the program by double clicking outside the thinstall container, it crashes. So, I forgot to allocate memory somewhere, and the thinstall container allocates it (in theory). Can you do the same?
Answer the question
In order to leave comments, you need to log in
Read these explanations first. Realize that there are 2 fundamentally different ways of storing information - on the stack and in "dynamic memory". Objects on the stack do not need to be allocated additional memory, and they are automatically deleted when the function exits.
Of course, you can't allocate memory automatically. The fact is that often we do not know the size of the memory that needs to be allocated. However, in most cases, you can use standard data types, such as std::vector, which write these operations for you. In real code, there may be almost no manually called delete operations due to the use of "smart pointers".
In your case, it's far from certain that this is the problem. Perhaps you're accessing the boundaries of some array, or trying to re-delete something, or one of dozens of other reasons. The different behavior may be due to different debug/release build modes, or, most likely, you are "lucky" in the virtual machine, and you do not get out of the memory reserved for your application.
PS Read smart books on C ++, you can't do without it. Start with this one, for example.
Maybe it's better for you to catch the error, for example, run it under a debugger and see where and why it crashes? :-)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question