]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use a smart pointer instead of a raw pointer. 4564/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 1 Jul 2017 05:28:12 +0000 (23:28 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 1 Jul 2017 05:28:12 +0000 (23:28 -0600)
Note that std::unique_ptr<T[]> automatically calls operator delete[]
upon destruction.

include/deal.II/dofs/dof_handler.h
source/dofs/dof_handler.cc

index 7df9f82c5cdf94b2c5d30662739703ea6cccbc3d..6c1a2e9c240a8c81135bc84d47b789d22f066561 100644 (file)
@@ -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
      * <code>dofs_per_vertex * (level-coarsest_level)</code>.
      */
-    types::global_dof_index *indices;
+    std::unique_ptr<types::global_dof_index[]> indices;
   };
 
   /**
index 3b38e91e1858b30a83372af04f0240654bcfe240..811db8e0da4f9f0a0fa40ec85c39e1fde15827ff 100644 (file)
@@ -1520,31 +1520,16 @@ template <int dim, int spacedim>
 DoFHandler<dim, spacedim>::MGVertexDoFs::MGVertexDoFs ()
   :
   coarsest_level (numbers::invalid_unsigned_int),
-  finest_level (0),
-  indices (nullptr)
+  finest_level (0)
 {}
 
 
 
-template <int dim, int spacedim>
-DoFHandler<dim, spacedim>::MGVertexDoFs::~MGVertexDoFs ()
-{
-  delete[] indices;
-}
-
-
-
 template <int dim, int spacedim>
 void DoFHandler<dim, spacedim>::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<dim, spacedim>::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 ();
 }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.