<div dir="ltr">well, as for the atom size in the GUI objects I'm using getbytes/freebytes and I guess that's the way to go.<div><br></div><div>as for the other issue, it's for a median~ external that takes medians and we're now using malloc/realloc for a temp t_float variable that gets the block size value inside the "dsp" function. see => <a href="https://github.com/porres/pd-else/blob/master/Classes/Source/median~.c#L78">https://github.com/porres/pd-else/blob/master/Classes/Source/median~.c#L78</a></div><div><br></div><div>I use this to get the median of bits of a signal block from FFT amplitudes, so, yeah, block sizes can be big but not too big.</div><div><br></div><div>anyway, seems to be working fine but if you have suggestions I'm all ears.</div><div><br></div><div>thanks a lot</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em sex., 4 de dez. de 2020 às 11:43, Christof Ressi <<a href="mailto:info@christofressi.com">info@christofressi.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>alloca() "allocates" memory on the stack. This is done by simply
      incrementing the stack pointer. So it's extremely fast and - more
      importantly - equally fast for all sizes.<br>
    </p>
    <p>malloc(), on the other hand, actually uses the system memory
      allocator which can take arbitrarily long and might even block!<br>
    </p>
    <p>Generally, you should avoid using any malloc() in real-time code
      paths. Instead, pre-allocate temporary buffers (e.g. in the "dsp"
      method) or allocate on the stack (but note the caveats mentioned
      in the other mails).</p>
    <p>Christof<br>
    </p>
    <div>On 04.12.2020 03:28, Alexandre Torres
      Porres wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">I'm using getbytes and freebytes for now, any
        disadvantages over alloca?
        <div><br>
        </div>
        <div>thanks!</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">Em qui., 3 de dez. de 2020 às
          20:59, David Rush <<a href="mailto:kumoyuki@gmail.com" target="_blank">kumoyuki@gmail.com</a>> escreveu:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div dir="ltr">
            <div dir="ltr">On Thu, 3 Dec 2020 at 23:15, Alexandre Torres
              Porres <<a href="mailto:porres@gmail.com" target="_blank">porres@gmail.com</a>>
              wrote:<br>
            </div>
            <div class="gmail_quote">
              <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                <div dir="ltr">Hi, when compiling ELSE for camomille in
                  windows, me and Esteban are getting some errors.
                  Offending pieces of code are when trying to do things
                  like
                  <div>
                    <div><br>
                    </div>
                    <div><span style="color:rgb(36,41,46);font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,monospace;font-size:12px;white-space:pre-wrap;background-color:rgb(255,251,221)">    t_atom at[ac];</span></div>
                  </div>
                </div>
              </blockquote>
              <div><br>
              </div>
              <div>If you want to maintain straight C compiler
                compatibility</div>
              <div><br>
              </div>
              <div>        t_atom* at = (t_atom*)malloc(ac *
                sizeof(t_atom));</div>
              <div><br>
              </div>
              <div>but you have to remember to free(at), &cet. You
                can avoid the free() if you HAVE_ALLOCA with</div>
              <div><br>
              </div>
              <div>
                <div>        t_atom* at = (t_atom*)alloca(ac *
                  sizeof(t_atom));</div>
              </div>
              <div><br>
              </div>
              <div>if you want to do it the C++ way without a
                std::vector<t_atom></div>
              <div><br>
              </div>
              <div>        t_atom* at = new t_atom[ac];</div>
              <div><br>
              </div>
              <div>but again you will have to</div>
              <div><br>
              </div>
              <div>        delete at;</div>
              <div><br>
              </div>
              <div>For my own externals, I write them all in C++ and use
                STL. Making the change from the C-world allocation of PD
                to the C++ world is not so hard, but it does involve a
                tiny bit of trickery which I only justify through
                expediency.</div>
              <div><br>
              </div>
              <div>- d</div>
            </div>
          </div>
        </blockquote>
      </div>
      <br>
      <fieldset></fieldset>
      <pre>_______________________________________________
Pd-dev mailing list
<a href="mailto:Pd-dev@lists.iem.at" target="_blank">Pd-dev@lists.iem.at</a>
<a href="https://lists.puredata.info/listinfo/pd-dev" target="_blank">https://lists.puredata.info/listinfo/pd-dev</a>
</pre>
    </blockquote>
  </div>

_______________________________________________<br>
Pd-dev mailing list<br>
<a href="mailto:Pd-dev@lists.iem.at" target="_blank">Pd-dev@lists.iem.at</a><br>
<a href="https://lists.puredata.info/listinfo/pd-dev" rel="noreferrer" target="_blank">https://lists.puredata.info/listinfo/pd-dev</a><br>
</blockquote></div>