[ODE] About "malloc" patch

Anton Savin anton at targem.ru
Mon Oct 4 17:35:08 MST 2004


Hi all,

I've just downloaded the latest snapshot of ODE and found there tons
of code like following:

  ALLOCA(dReal,fe,n6*sizeof(dReal));
#ifdef dUSE_MALLOC_FOR_ALLOCA
    if (fe == NULL) {
      UNALLOCA(invM);
      UNALLOCA(ofs);
      UNALLOCA(info);
      UNALLOCA(invI);
      UNALLOCA(I);
      UNALLOCA(joint);
      dMemoryFlag = d_MEMORY_OUT_OF_MEMORY;
      return;
    }
#endif

  ALLOCA(dReal,v,n6*sizeof(dReal));
#ifdef dUSE_MALLOC_FOR_ALLOCA
    if (v == NULL) {
      UNALLOCA(fe);
      UNALLOCA(invM);
      UNALLOCA(ofs);
      UNALLOCA(info);
      UNALLOCA(invI);
      UNALLOCA(I);
      UNALLOCA(joint);
      dMemoryFlag = d_MEMORY_OUT_OF_MEMORY;
      return;
    }
#endif

I suppose this is what is called "a patch that enables use of dynamic
memory". But who is shure that it's bug free? Has actually anyone
tested all these code paths?
And, most important: when there becomes another allocation, won't you
forget to UNALLOCAte it everywhere?

Shortly, why not use smart pointers?

Cheers,
Anton Savin.




More information about the ODE mailing list