Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Stack space not reused

$
0
0

Hi

I have a simple program

#include <stdio.h>

int main()
{
    {
        char buf1[2048];
        printf("buf1: %p\n", buf1);
    }
    {
        char buf2[2048];
        printf("buf2: %p\n", buf2);
    }
return 0;
}

I expect buf1 and buf2 to have the same adress since when buf2 is in scope, buf1 is out of scope.

I have tested on Visual 2010 and g++ 4.8 and I have this result:

buf1: 0035F5A0

buf2: 0035F5A0

On Intel 14.0

buf1: 002FEC80

buf2: 002FF480

In practice I have a program with lots of inlining and lots of variables accumulated on the stack and I get some 4K-aliasing penalty so I'm investigating why my code is taking so much space on stack. And I use lots of scoping to, in theory, reuse the stack the most possibly.

Is there any way to force the compiler to depop from the stack the variable out of scope ?

Regards


Viewing all articles
Browse latest Browse all 1616

Trending Articles