From bf88c3e84a0584ba0bd5e24e6be44f7d872208ce Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 1 Apr 2010 06:43:05 +0000 Subject: [PATCH] Ref counting in SUPPORT,MESH, FIELD. valgrind =0. --- .../InterpolationOptionsTest.cxx | 32 +++++++++++-------- src/INTERP_KERNELTest/MeshTestToolkit.txx | 4 +-- src/RENUMBER/renumbering.cxx | 1 - 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/INTERP_KERNELTest/InterpolationOptionsTest.cxx b/src/INTERP_KERNELTest/InterpolationOptionsTest.cxx index bfd2f8a3d..949c3f0f8 100644 --- a/src/INTERP_KERNELTest/InterpolationOptionsTest.cxx +++ b/src/INTERP_KERNELTest/InterpolationOptionsTest.cxx @@ -46,32 +46,36 @@ namespace INTERP_TEST */ void InterpolationOptionsTest::test_InterpolationOptions() { string sourcename=INTERP_TEST::getResourceFile("square1.med"); - MEDMEM::MESH source_mesh (MED_DRIVER,sourcename,"Mesh_2"); + MEDMEM::MESH *source_mesh=new MEDMEM::MESH(MED_DRIVER,sourcename,"Mesh_2"); string targetname=INTERP_TEST::getResourceFile("square2.med"); - MEDMEM::MESH target_mesh (MED_DRIVER,targetname,"Mesh_3"); + MEDMEM::MESH *target_mesh=new MEDMEM::MESH(MED_DRIVER,targetname,"Mesh_3"); - MEDMEM::SUPPORT source_support(&source_mesh,"on All support"); - MEDMEM::FIELD source_field(&source_support,1); - double* value=const_cast(source_field.getValue()); - for (int i=0; i *source_field=new FIELD(source_support,1); + double* value=const_cast(source_field->getValue()); + for (int i=0; igetNumberOfElements(MED_EN::MED_ALL_ELEMENTS); i++) value[i]=1.0; - - MEDMEM::SUPPORT target_support(&target_mesh,"on All support"); - MEDMEM::FIELD target_field(&target_support,1); - double* targetvalue=const_cast(target_field.getValue()); - for (int i=0; iremoveReference(); + MEDMEM::SUPPORT *target_support=new MEDMEM::SUPPORT(target_mesh,"on All support"); + MEDMEM::FIELD *target_field=new FIELD(target_support,1); + double* targetvalue=const_cast(target_field->getValue()); + for (int i=0; igetNumberOfElements(MED_EN::MED_ALL_ELEMENTS); i++) targetvalue[i]=0.0; - + target_support->removeReference(); // Ok at this point we have our mesh in MED-Memory format. // Go to wrap med_source_mesh and med_target_mesh. - MEDNormalizedUnstructuredMesh<2,2> wrap_source_mesh(&source_mesh); - MEDNormalizedUnstructuredMesh<2,2> wrap_target_mesh(&target_mesh); + MEDNormalizedUnstructuredMesh<2,2> wrap_source_mesh(source_mesh); + MEDNormalizedUnstructuredMesh<2,2> wrap_target_mesh(target_mesh); // Go for interpolation... INTERP_KERNEL::Interpolation2D myInterpolator; //optionnal call to parametrize your interpolation. First precision, tracelevel, intersector wanted. myInterpolator.setPrecision(1e-7); myInterpolator.setPrintLevel(1); + source_mesh->removeReference(); + source_field->removeReference(); + target_field->removeReference(); + target_mesh->removeReference(); } diff --git a/src/INTERP_KERNELTest/MeshTestToolkit.txx b/src/INTERP_KERNELTest/MeshTestToolkit.txx index ddfb21e94..5c1da0939 100644 --- a/src/INTERP_KERNELTest/MeshTestToolkit.txx +++ b/src/INTERP_KERNELTest/MeshTestToolkit.txx @@ -124,8 +124,8 @@ namespace INTERP_TEST } const double *tabS = f->getValue(); std::copy(tabS,tabS+mesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS),tab); - delete sup; - delete f; + sup->removeReference(); + f->removeReference(); } /** diff --git a/src/RENUMBER/renumbering.cxx b/src/RENUMBER/renumbering.cxx index 44eac9a2e..df273a71e 100644 --- a/src/RENUMBER/renumbering.cxx +++ b/src/RENUMBER/renumbering.cxx @@ -334,7 +334,6 @@ int main (int argc, char** argv) } int drv=newField.addDriver(MED_DRIVER,filename_out,field_names[ifield]); newField.write(drv); - delete (SUPPORT *) newField.getSupport(); } t_field=clock(); cout << " : " << (t_field-t_family)/(double) CLOCKS_PER_SEC << "s" << endl; -- 2.39.2