Back to index

salome-med  6.5.0
Functions
MEDMEMTest_Array_fault.cxx File Reference
#include "MEDMEM_Array.hxx"
#include <cmath>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Check method shallowCopy()

Function Documentation

int main ( int  argc,
char **  argv 
)

Check method shallowCopy()

Definition at line 30 of file MEDMEMTest_Array_fault.cxx.

{
  int ld = 7, nb = 4;
  double rr = 13.0, h0 = 7.0;
  double * aValues = new double [ld * nb];
  for (int nn = 0; nn < nb; nn++) {
    aValues[nn*ld + 0] = nn;
    aValues[nn*ld + 1] = rr * cos(nn * M_PI/4.);
    aValues[nn*ld + 2] = rr * sin(nn * M_PI/4.);
    aValues[nn*ld + 3] = h0 + nn;
    aValues[nn*ld + 4] = 2.0 * rr * cos(nn * M_PI/4.);
    aValues[nn*ld + 5] = 2.0 * rr * sin(nn * M_PI/4.);
    aValues[nn*ld + 6] = h0 - nn;
  }

  MEDARRAY<double> * aSpiral =
    new MEDARRAY<double> (aValues, ld, nb, MED_EN::MED_FULL_INTERLACE,
                          /*shallowCopy=*/false, /*ownershipOfValues=*/false);

  // Check method shallowCopy()
  MEDARRAY<double> shc;

  // (BUG) MEDARRAY<T>::shallowCopy() usage leads to memory leaks,
  // because on attempt to free both arrays we have Segmentation Fault
  shc.shallowCopy(*aSpiral);

  delete aSpiral;

  // hangs up
  //MEDARRAY<double> arr (10, 10);
  //MEDARRAY<double> shc;
  //shc.shallowCopy(arr);

  // Segmentation fault
  //MEDARRAY<double>* arr = new MEDARRAY<double> (10, 10);
  //MEDARRAY<double>* shc = new MEDARRAY<double> (10, 10);
  //shc->shallowCopy(*arr);
  //delete arr;
  //delete shc;
}

Here is the call graph for this function: