From: Wolfgang Bangerth Date: Sat, 1 Jul 2017 05:28:12 +0000 (-0600) Subject: Use a smart pointer instead of a raw pointer. X-Git-Tag: v9.0.0-rc1~1457^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ab233bbfb6b2cf76dec7ba5fb0b695b5e462957;p=dealii.git Use a smart pointer instead of a raw pointer. Note that std::unique_ptr automatically calls operator delete[] upon destruction. --- diff --git a/include/deal.II/dofs/dof_handler.h b/include/deal.II/dofs/dof_handler.h index 7df9f82c5c..6c1a2e9c24 100644 --- a/include/deal.II/dofs/dof_handler.h +++ b/include/deal.II/dofs/dof_handler.h @@ -965,11 +965,6 @@ private: */ MGVertexDoFs (); - /** - * Destructor. - */ - ~MGVertexDoFs (); - /** * A function that is called to allocate the necessary amount of memory to * store the indices of the DoFs that live on this vertex for the given @@ -1032,7 +1027,7 @@ private: * The starting offset of the DoFs that belong to a @p level are given by * dofs_per_vertex * (level-coarsest_level). */ - types::global_dof_index *indices; + std::unique_ptr indices; }; /** diff --git a/source/dofs/dof_handler.cc b/source/dofs/dof_handler.cc index 3b38e91e18..811db8e0da 100644 --- a/source/dofs/dof_handler.cc +++ b/source/dofs/dof_handler.cc @@ -1520,31 +1520,16 @@ template DoFHandler::MGVertexDoFs::MGVertexDoFs () : coarsest_level (numbers::invalid_unsigned_int), - finest_level (0), - indices (nullptr) + finest_level (0) {} -template -DoFHandler::MGVertexDoFs::~MGVertexDoFs () -{ - delete[] indices; -} - - - template void DoFHandler::MGVertexDoFs::init (const unsigned int cl, const unsigned int fl, const unsigned int n_dofs_per_vertex) { - if (indices != nullptr) - { - delete[] indices; - indices = nullptr; - } - coarsest_level = cl; finest_level = fl; dofs_per_vertex = n_dofs_per_vertex; @@ -1554,9 +1539,12 @@ void DoFHandler::MGVertexDoFs::init (const unsigned int cl, const unsigned int n_levels = finest_level - coarsest_level + 1; const unsigned int n_indices = n_levels * dofs_per_vertex; - indices = new types::global_dof_index[n_indices]; - std::fill (indices, indices+n_indices, numbers::invalid_dof_index); + indices.reset (new types::global_dof_index[n_indices]); + std::fill (indices.get(), indices.get()+n_indices, + numbers::invalid_dof_index); } + else + indices.reset (); }