Skip to content

[BlockVector] Defer memory management to std::vector.

Jö Fahlke requested to merge fix-blockvector-memory-management into master

Stop doing memory management ourselves, use a std::vector instead. This has the advantage that allocation, deallocation, construction and destruction of elements is handled for us using the supplied allocator in an exception-safe manner.

This has the disadvantage of using an extra pointer and an extra size_type in base_array_unmanaged, which are kept syncronized with the std::vector used as storage. Anything else would require interface modification of base_array_unmanaged and block_vector_unmanaged, which in turn would require modifications to BlockVectorWindow, MatrixBase, and VariableBlockVector and make this patch even larger.

This adds a swap() operation and move-construction/assignment to BlockVector.

The one-argument versions of resize() and reserve() now behave exactly as they do for std::vector. This means that using reserve() to shrink the capacity of a BlockVector no longer has any effect. Apart from that, the behaviour with regard to capacity on copy and move has also changed to that of std::vector: copying will only expand the capacity of the copied-to vector to accomodate the size of the copied-from vector, not necessarily it's capacity.

This deprecates the two-argument versions of resize() and reserve(), and makes them behave exactly the same as the one-argument versions, ignoring the second argument. The second argument specified whether or not to copy the old values upon reallocation. This conflicted with the common container semantics of always copying/moving. For resize(), it also conflicted with the common signature where the second argument specifies the value for newly created elements.

There were only two uses of the two-argument version of resize() in dune-istl that triggered in the unit tests (both in arpackpp.hh), and those had no effect different from the the one-argument version, because the BlockVectors were empty before the resize().

Fixes: #41 (closed)
Requires:

Intent-to-merge: 2018-05-30.

Edited by Jö Fahlke

Merge request reports

Loading