Consider the following function:
void Foo()
{
std::string s = "Hello";
}
In the above case where is the string allocated? Some pages (like this) says it's on the heap and Microsoft says it depends on the size. And how can I make it for sure on the heap and on the stack (if I want to avoid using new()
)?
Consider another function:
void Foo2()
{
char *c = "Hello";
}
In this case I supposed it is on the stack, but as soon as I checked its assembly via MS Visual C++ I think it is on the heap. Is it true?
And where is char c[] = "Hello"
?
I'm using VC12, but I would like to know what about g++ too.
It's important me because of the exception handling. Because in case of an unwinding stack I really lose data if it's created on the heap and in other hand there is no problem, but the stack can be too big.