Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary memory allocation. #13014

Merged
merged 1 commit into from Dec 1, 2021
Merged

Conversation

bangerth
Copy link
Member

While looking around what is necessary for #13005/#12998/#12993, I also realized an inefficiency: In one place, we resize a vector, and then copy into that vector, but the copy operation releases the previously allocated memory and re-allocates it. We can avoid this.

/rebuild

@drwells
Copy link
Member

drwells commented Nov 30, 2021

Can we just use the default copy constructor?

@bangerth
Copy link
Member Author

No, we can't, because we need to call Subscriptor(), not Subscriptor(src).

@masterleinad
Copy link
Member

No, we can't, because we need to call Subscriptor(), not Subscriptor(src).

But they do exactly the same, see

inline Subscriptor::Subscriptor()
: counter(0)
, object_info(nullptr)
{}
inline Subscriptor::Subscriptor(const Subscriptor &)
: counter(0)
, object_info(nullptr)
{}
.

@bangerth
Copy link
Member Author

Hm. I had not realized this. I still like it being explicit -- we have plenty of other places where we are explicit about this as well:

> grep -r ': Subscriptor()' include/ source/
include/deal.II/lac/vector.templates.h:  : Subscriptor()
include/deal.II/lac/la_parallel_vector.templates.h:      : Subscriptor()
include/deal.II/lac/read_write_vector.h:    : Subscriptor()
include/deal.II/lac/read_write_vector.h:    : Subscriptor()
include/deal.II/lac/read_write_vector.h:    : Subscriptor()
include/deal.II/lac/read_write_vector.h:    : Subscriptor()
include/deal.II/lac/affine_constraints.h:  : Subscriptor()
include/deal.II/lac/trilinos_tpetra_vector.templates.h:      : Subscriptor()
include/deal.II/lac/trilinos_tpetra_vector.templates.h:      : Subscriptor()
include/deal.II/lac/trilinos_tpetra_vector.templates.h:      : Subscriptor()
include/deal.II/matrix_free/operators.h:    : Subscriptor()
include/deal.II/matrix_free/operators.h:    : Subscriptor()
include/deal.II/matrix_free/matrix_free.templates.h:  : Subscriptor()
include/deal.II/matrix_free/matrix_free.templates.h:  : Subscriptor()
include/deal.II/base/table.h:  : Subscriptor()
source/lac/trilinos_sparsity_pattern.cc:    : Subscriptor()
source/lac/trilinos_epetra_vector.cc:      : Subscriptor()
source/lac/trilinos_epetra_vector.cc:      : Subscriptor()
source/lac/trilinos_epetra_vector.cc:      : Subscriptor()
source/lac/trilinos_vector.cc:      : Subscriptor()
source/lac/dynamic_sparsity_pattern.cc:  : Subscriptor()
source/lac/chunk_sparsity_pattern.cc:  : Subscriptor()
source/lac/petsc_vector_base.cc:    : Subscriptor()
source/lac/petsc_vector_base.cc:    : Subscriptor()
source/lac/block_sparsity_pattern.cc:  : Subscriptor()
source/lac/trilinos_precondition.cc:    : Subscriptor()
source/base/quadrature.cc:  : Subscriptor()
source/base/quadrature.cc:  : Subscriptor()
source/base/quadrature.cc:  : Subscriptor()
source/base/quadrature.cc:  : Subscriptor()

@drwells
Copy link
Member

drwells commented Dec 1, 2021

Lets just merge this as-is - this PR is already an improvement. We can worry about consistently using default copy constructors later.

@drwells drwells merged commit 1d2117d into dealii:master Dec 1, 2021
@bangerth bangerth deleted the aligned-2 branch December 1, 2021 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants