If my application is out of memory when i call new() i will get exception and malloc() i will get 0 pointer.
But what if i call a method with some local variables? They occupy memory too. Is there some way to reserve memory for "normal" variables? So that even though new() throws exception i can just catch it, fix stuff and still call methods like usual.
Your data is allocated in one of three ways:
You generally shouldn't run out of stack space unless you perform some heavy recursion though.
THe C++ language doesn't provide any mechanism for reserving memory for local variables. Your specific C++ implementation and/or operating system may provide some means of increasing the total stack size, but this is not normally necessary.
Note also that if a call to new does fail, there is probably very little you can practically do to recover from it. Many people (me included) no longer bother checking for new failure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With