title: Memory-optimizing recursive calls in C
body: <p>I have a recursive function which can be written like:</p>
  
  <pre><code>void func(TypeName *dataStructure, LL_Node **accumulator) {
      func(datastructure-&gt;left, accumulator);
      func(datastructure-&gt;right, accumulator);
  
      {
          char buffer[1000];
          // do some stuff
      }
  
      return;
  }        
  </code></pre>
  
  <p>I know that in reality the buffer is being allocated at the beginning of the function and putting the statement in a nested scope block <a href="https://stackoverflow.com/questions/2759371/in-c-do-braces-act-as-a-stack-frame">doesn't actually use a new stack frame</a>. But I don't want the compiler to allocate an exponential number of 1000-byte buffers at once, when they can be allocated and thrown away one at a time as each level returns.</p>
  
  <p>Should I use outside global variables? A call to a helper function to force the buffer to be allocated after the recursive call? What I'm really fishing for here is advice on the cleanest, most C-idiomatic way of forcing this behavior.</p>
  
  <p>Edit: One add-on question. If the exact same <code>accumulator</code> will be passed to every call of <code>func</code>, is it unheard of to leave the <code>accumulator</code> pointer in a global variable rather than pushing it onto the stack with every call?</p>