title: Passing struct pointer vs passing struct
body: <p>I was recently writing a lot of programs that pass <code>struct</code>s around functions, to avoid global variables. However, I was wondering whether passing the <code>struct</code> itself or its pointer is more efficient. It sounds like it should be, because pointers are (on my 64-bit GNU/Linux system) 8 bytes, while a <code>struct</code> full of pointers is obviously a lot more than that.</p>
  
  <p>However, if I have this <code>struct</code>:</p>
  
  <pre><code>struct Point {
      int x;
      int y;
  }
  </code></pre>
  
  <p>which is 8 bytes, the same size as the pointer, is it better to pass the entire <code>struct</code> to a function, or to pass a pointer? I am fairly proficient with C memory allocation, so it isn't a problem to use <code>malloc</code> and friends when initialising pointers.</p>
  
  <p>Another thought that I had was that passing structures directly could use up a lot of stack space if they are large. However simply using pointers would use up the memory, which can be <code>free</code>ed easily.</p>