Subject: [Boost-bugs] [Boost C++ Libraries] #7106: multi_array::resize switches to default-constructed allocator
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-07-09 14:00:57
#7106: multi_array::resize switches to default-constructed allocator
-------------------------------------+--------------------------------------
Reporter: bmerry@⦠| Owner: garcia
Type: Bugs | Status: new
Milestone: To Be Determined | Component: multi_array
Version: Boost Development Trunk | Severity: Problem
Keywords: allocator |
-------------------------------------+--------------------------------------
I've run into this with 1.46 but eyeballing the code on trunk it doesn't
seem to have changed.
The implementation of `resize` starts like this:
{{{
// build a multi_array with the specs given
multi_array new_array(ranges,this->storage_order());
}}}
However, no allocator is passed to this constructor. If `*this` has a non-
default allocator, then it will not get used to allocate the resized
storage, and furthermore, the default allocator in new_array will get
swapped in to `*this`, wiping out the custom allocator.
This can be fixed by changing this line to
{{{
multi_array new_array(ranges,this->storage_order(),allocator_);
}}}
so that the new array uses the same allocator as the current one.
I'll attach a test case that demonstrates the issue by using an allocator
class where instances are named and report the allocations they make (I'm
using a more complex version of this to track memory usage, which is where
I hit the bug). It currently reports
{{{
Allocated 17 bytes [name = vector]
Allocated 0 bytes [name = multi_array]
Allocated 15 bytes [name = default]
}}}
but with the fix applied it reports
{{{
Allocated 17 bytes [name = vector]
Allocated 0 bytes [name = multi_array]
Allocated 15 bytes [name = multi_array]
}}}
It is the final line where the resize is taking place.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7106> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC