<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>I am writing a DSP extern that can have a any number of outlets
      depending on the creation arguments (like [fexpr~], e.g.). In
      order to interact with the outlets in the <tt>XXX_tilde_perform</tt>
      loop, I made a member of my <tt>t_XXX_tilde</tt> data structure
      thus:</p>
    <p><tt>t_sample **lcl_outs;</tt></p>
    <p>Then, when I know how many outlets I need, I allocate the
      appropriate amount of memory. In the<tt> XXX_tilde_perform</tt>
      loop, I set the pointers to those handed by Pd's scheduling engine
      in the standard way:</p>
    <p><tt>for(int i=0;i<x->nouts;i++)</tt></p>
    <p><tt>    x->lcl_outs[i] = w[2+i];</tt></p>
    <p>I found that this would sporadically crash Pd when turning the
      DSP engine on and off and (sometimes) when
      connecting/disconnecting to one of the outlets. I think that I
      have solved this problem by copying my pointers at the head of the
      <tt>XXX_tilde_perform</tt> method to a local variable:</p>
    <p><tt>t_sample **lcl_outs = x->lcl_outs;</tt></p>
    <p><tt>for(int i=0;i<x->nouts;i++)</tt></p>
    <tt>
    </tt>
    <p><tt>    lcl_outs[i] = w[2+i];</tt></p>
    <p>Everything <i>appears</i> to work now. I assume that somehow
      Pd's engine is rubbing my <tt>x->lcl_outs</tt> ptr off of the
      stack. Thus, by copying it to another ptr I avoid this problem
      because my OS still knows where the allocated memory is. That is
      to say, when Pd gets rid of whatever<tt> w[2] </tt>is, it then
      removes the ptr <tt>lcl_outs</tt>, not <tt>x->lcl_outs</tt>,
      which still has memory behind it.<br>
    </p>
    <p>Am I reading this right? I am not at all confident that I have
      truly solved this problem. If anyone has any insight, I'd like to
      know too.<br>
    </p>
    <p>Thanks!</p>
    <p>David<br>
    </p>
  </body>
</html>