From: kronbichler Date: Tue, 3 Dec 2013 21:15:05 +0000 (+0000) Subject: Use std::vector instead of manually allocating memory X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e214081ee2317dd270d3a99c1e5b88296497e200;p=dealii-svn.git Use std::vector instead of manually allocating memory git-svn-id: https://svn.dealii.org/trunk@31863 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/constraint_matrix.templates.h b/deal.II/include/deal.II/lac/constraint_matrix.templates.h index 44dd38ae4b..20a85f4c66 100644 --- a/deal.II/include/deal.II/lac/constraint_matrix.templates.h +++ b/deal.II/include/deal.II/lac/constraint_matrix.templates.h @@ -1276,71 +1276,55 @@ namespace internals { DataCache () : - element_size (0), - data (0), - n_used_elements(0) + element_size (0) {} - ~DataCache() - { - delete [] data; - data = 0; - } - void reinit () { if (element_size == 0) { + // the initial size allows for 16 global dofs that are reached with + // each having up to 6 entries. But we allow this size to change in + // both directions element_size = 6; - data = new std::pair [20*6]; - individual_size.resize(20); + data.reserve(16*element_size); + individual_size.reserve(16); } - n_used_elements = 0; + individual_size.resize(0); } size_type element_size; - std::pair *data; + std::vector > data; std::vector individual_size; - size_type n_used_elements; - size_type insert_new_index (const std::pair &pair) { if (element_size == 0) reinit(); - if (n_used_elements == individual_size.size()) - { - std::pair *new_data = - new std::pair [2*individual_size.size()*element_size]; - memcpy (new_data, data, individual_size.size()*element_size* - sizeof(std::pair)); - delete [] data; - data = new_data; - individual_size.resize (2*individual_size.size(), 0); - } - size_type index = n_used_elements; + const unsigned int index = individual_size.size(); + individual_size.push_back(1); + data.resize(individual_size.size()*element_size); data[index*element_size] = pair; individual_size[index] = 1; - ++n_used_elements; return index; } void append_index (const size_type index, const std::pair &pair) { - AssertIndexRange (index, n_used_elements); + AssertIndexRange (index, individual_size.size()); const size_type my_size = individual_size[index]; if (my_size == element_size) { - std::pair *new_data = - new std::pair [2*individual_size.size()*element_size]; - for (size_type i=0; i)); - delete [] data; - data = new_data; + std::vector > + new_data(2*individual_size.size()*element_size*2); + for (size_type i=0; i