Following on from a previous question here I've been looking at the output from the VS2015 code analysis and see a warning for high stack usage in a function that can be simplified as follows;
class base
{
public:
virtual void Process();
Buffer[10000];
};
class derived1 : public base
{
public:
void Process();
}
class derived2 : public base
{
public:
void Process();
}
void MyFunc(int x)
{
switch(x)
{
case 0:
{
derived1 x;
x.Process();
} break;
case 1:
{
derived2 y;
y.Process();
} break;
}
}
The analysis warns me that I'm using 20,000 bytes of stack in MyFunc
. Is this the case, in that all stack variables are allocated at function entry and deallocated at function exit, rather than as they are constructed and destructed with scope? Just curious (but not quite curious enough to go wading through the assembly output ;) ) A related question here doesn't quite give me the answer I'm looking for.