Wednesday, 15 August 2012

c++ - Is variable allocated on stack if i return before its declaration? -



c++ - Is variable allocated on stack if i return before its declaration? -

assume have function rough construction looks this:

int arecursivefunction(const somelargestructure *a, int x) { if (end recursion) homecoming 0; // ... if (something true) homecoming arecursivefunction(a, x+1)+1; // ... somelargestructure re-create = *a; alter(&copy); homecoming arecursivefunction(&copy, x); }

what need know is, performance reasons, whether space copy (which big structure) created on stack in 90 % of cases function ends before point. or not matter? depend on compiler? improve separate part function?

thanks.

edit: clarify, sizeof(somelargestructure) around 500, has basic types , arrays (no special constructors or assignment operators etc.).

edit 2: alright, conclusion seems stack space allocated every time doesn't impact performance. stack overflow not issue here, case closed.

on platforms, maximum stack space might needed allocated on function entry. allocating stack space addition, amount of space allocated has no effect on performance.

your question reads premature optimization me though. isn't algorithmic issue , don't have measured performance issue. why thinking micro-optimizations?

c++

No comments:

Post a Comment