Back to index

salome-med  6.5.0
MEDMEMTest_Array_fault.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDMEM_Array.hxx"
00021 
00022 #include <cmath>
00023 
00024 using namespace std;
00025 using namespace MEDMEM;
00026 
00030 int main (int argc, char** argv)
00031 {
00032   int ld = 7, nb = 4;
00033   double rr = 13.0, h0 = 7.0;
00034   double * aValues = new double [ld * nb];
00035   for (int nn = 0; nn < nb; nn++) {
00036     aValues[nn*ld + 0] = nn;
00037     aValues[nn*ld + 1] = rr * cos(nn * M_PI/4.);
00038     aValues[nn*ld + 2] = rr * sin(nn * M_PI/4.);
00039     aValues[nn*ld + 3] = h0 + nn;
00040     aValues[nn*ld + 4] = 2.0 * rr * cos(nn * M_PI/4.);
00041     aValues[nn*ld + 5] = 2.0 * rr * sin(nn * M_PI/4.);
00042     aValues[nn*ld + 6] = h0 - nn;
00043   }
00044 
00045   MEDARRAY<double> * aSpiral =
00046     new MEDARRAY<double> (aValues, ld, nb, MED_EN::MED_FULL_INTERLACE,
00047                           /*shallowCopy=*/false, /*ownershipOfValues=*/false);
00048 
00049   // Check method shallowCopy()
00050   MEDARRAY<double> shc;
00051 
00052   // (BUG) MEDARRAY<T>::shallowCopy() usage leads to memory leaks,
00053   // because on attempt to free both arrays we have Segmentation Fault
00054   shc.shallowCopy(*aSpiral);
00055 
00056   delete aSpiral;
00057 
00058   // hangs up
00059   //MEDARRAY<double> arr (10, 10);
00060   //MEDARRAY<double> shc;
00061   //shc.shallowCopy(arr);
00062 
00063   // Segmentation fault
00064   //MEDARRAY<double>* arr = new MEDARRAY<double> (10, 10);
00065   //MEDARRAY<double>* shc = new MEDARRAY<double> (10, 10);
00066   //shc->shallowCopy(*arr);
00067   //delete arr;
00068   //delete shc;
00069 }