title: Which allocation is faster ? malloc vs local variable
body: <p>Which is preferable way to allocate memory for a function that is frequently allocating and freeing memory ? Assume this function is getting called around 500 to 1000 times a second on a 1GHz Processor.</p>
  
  <p>(Please ignore static and global variables/allocation. I am interested only this specific case:)</p>
  
  <pre><code>void Test()
  {
      ptr=malloc(512)   // 512 bytes
      ...
      free(ptr) 
  }
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>void Test()
  {
       struct MyStruct localvar; // 512 byte sized structure
       ... 
  }
  </code></pre>