Consider the next piece of code
class foo {
public:
void f() {
char buffer[1024];
memset(buffer, NULL, 1024);
read_some_input_to_buffer(buffer, 1024);
}
};
class bar {
public:
void f() {
memset(_myPrivateBuffer, NULL, 1024);
read_some_input_to_buffer(_myPrivateBuffer, 1024);
}
private:
char _myPrivateBuffer[1024];
};
Will bar::f() work faster than foo::f()? As I see it, the buffer already exists in bar, so the compiler won't allocate memory for it on the stack when the function is called? Or am I wrong and the memory is already allocated before foo::f() is called as well?