title: self-avoiding random walks on a lattice in C with recursion - memory allocation
body: <p>I want to compute (for a project) self-avoiding random walks by using a recursive function. I've managed to do that with two arrays <code>StepX</code> and <code>StepY</code> that keep track of the x and y, respectively, of the path. The recursive function is something like:</p>
  
  <pre><code>go(int x, int y, int n,int* StepX,int* StepY)
  </code></pre>
  
  <p>which can be summarised at "for the n-th step go at (x,y) remembering that you've been in StepX and StepY".</p>
  
  <p>The project is finished and I am happy, but I would like to know how to make it work using (also) a lattice, with 1 and 0 describing visited / not yet visited locations, in order to improve its speed.</p>
  
  <p>I thought that extending the function as </p>
  
  <pre><code>go(int x, int y, int n,int* StepX,int* StepY, int* lattice)
  </code></pre>
  
  <p>would be what I was looking for, because I thought that everytime the function <code>go</code> is called, it creates a new copy of the lattice and works with it. But apparently this is not the case, since after having explored one direction (and after having reached the maximum level of the recursion allowed), going to a lower level of recursion, the lattice is still the same, with the visited location (of the deeper level) marked , while I wanted each level of the recursion to work on a different copy of the lattice.</p>
  
  <p>Is it a wrong expectation? Is it just a wrong implementation? Any advice to reduce the memory size required by this approach?</p>
  
  <p>My code (actually I didn't write most of it) can be found here: <a href="https://gist.github.com/4144833" rel="nofollow">https://gist.github.com/4144833</a></p>
  
  <p>Be patient, I'm not an experienced programmer.</p>