From: Wolfgang Bangerth Date: Sat, 8 Aug 2015 02:58:21 +0000 (-0500) Subject: Use a std_cxx11::unique_ptr in FEValues. X-Git-Tag: v8.4.0-rc2~643^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e0e0361cb4713eccaa8ad83642f56335663db42;p=dealii.git Use a std_cxx11::unique_ptr in FEValues. Specifically, use it for the internal data objects of mapping and finite element. These pointers are internally created and used in the FEValues class. They are not shared by any external interface. Using a unique_ptr ensures no memory leaks. --- diff --git a/include/deal.II/fe/fe_values.h b/include/deal.II/fe/fe_values.h index 62d0f27bcf..179e007c5c 100644 --- a/include/deal.II/fe/fe_values.h +++ b/include/deal.II/fe/fe_values.h @@ -2334,12 +2334,12 @@ protected: /** * Internal data of mapping. */ - SmartPointer::InternalDataBase,FEValuesBase > mapping_data; + std_cxx11::unique_ptr::InternalDataBase> mapping_data; /** * Internal data of finite element. */ - SmartPointer::InternalDataBase,FEValuesBase > fe_data; + std_cxx11::unique_ptr::InternalDataBase> fe_data; /** * Original update flags handed to the constructor of FEValues. diff --git a/source/fe/fe_values.cc b/source/fe/fe_values.cc index 40548fbae9..6f18dc0fbe 100644 --- a/source/fe/fe_values.cc +++ b/source/fe/fe_values.cc @@ -2161,8 +2161,6 @@ FEValuesBase::FEValuesBase (const unsigned int n_q_points, dofs_per_cell (dofs_per_cell), mapping(&mapping, typeid(*this).name()), fe(&fe, typeid(*this).name()), - mapping_data(0, typeid(*this).name()), - fe_data(0, typeid(*this).name()), fe_values_views_cache (*this) { Assert (n_q_points > 0, @@ -2177,25 +2175,6 @@ FEValuesBase::FEValuesBase (const unsigned int n_q_points, template FEValuesBase::~FEValuesBase () { - // delete those fields that were - // created by the mapping and - // finite element objects, - // respectively, but of which we - // have assumed ownership - if (fe_data != 0) - { - typename FiniteElement::InternalDataBase *tmp1=fe_data; - fe_data=0; - delete tmp1; - } - - if (mapping_data != 0) - { - typename Mapping::InternalDataBase *tmp1=mapping_data; - mapping_data=0; - delete tmp1; - } - tria_listener.disconnect (); } @@ -3427,8 +3406,8 @@ FEValues::initialize (const UpdateFlags update_flags) // FE and the Mapping can store // intermediate data used across // calls to reinit - this->mapping_data = this->mapping->get_data(flags, quadrature); - this->fe_data = this->fe->get_data(flags, *this->mapping, quadrature); + this->mapping_data.reset (this->mapping->get_data(flags, quadrature)); + this->fe_data.reset (this->fe->get_data(flags, *this->mapping, quadrature)); // initialize the base classes internal::FEValues::MappingRelatedData::initialize(this->n_quadrature_points, flags); @@ -3657,8 +3636,8 @@ FEFaceValues::initialize (const UpdateFlags update_flags) // FE and the Mapping can store // intermediate data used across // calls to reinit - this->mapping_data = this->mapping->get_face_data(flags, this->quadrature); - this->fe_data = this->fe->get_face_data(flags, *this->mapping, this->quadrature); + this->mapping_data.reset (this->mapping->get_face_data(flags, this->quadrature)); + this->fe_data.reset (this->fe->get_face_data(flags, *this->mapping, this->quadrature)); // initialize the base classes internal::FEValues::MappingRelatedData::initialize(this->n_quadrature_points, flags); @@ -3806,10 +3785,10 @@ FESubfaceValues::initialize (const UpdateFlags update_flags) // FE and the Mapping can store // intermediate data used across // calls to reinit - this->mapping_data = this->mapping->get_subface_data(flags, this->quadrature); - this->fe_data = this->fe->get_subface_data(flags, + this->mapping_data.reset (this->mapping->get_subface_data(flags, this->quadrature)); + this->fe_data.reset (this->fe->get_subface_data(flags, *this->mapping, - this->quadrature); + this->quadrature)); // initialize the base classes internal::FEValues::MappingRelatedData::initialize(this->n_quadrature_points, flags);