Skip to content

Commit 548496f

Browse files
committed
Fixes #328 ("boost::container::deque stores a redundant copy of the allocator, increasing size")
1 parent bf058bc commit 548496f

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

doc/container.qbk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,9 +1458,11 @@ use [*Boost.Container]? There are several reasons for that:
14581458
* Implemented overaligned allocation support for `new_allocator` and `pmr::new_delete_resource()`:
14591459
* If available, uses C++17's utilities under the `__cpp_aligned_new` feature.
14601460
* Uses alternative aligned allocation functions (`posix_memalign`, `aligned_alloc`, `_aligned_malloc`...) otherwise.
1461+
* Implemented overaligned allocation support for `adaptive_pool`and `node_allocator`
14611462
* Updated `basic_string` to the latest standard API: Added missing `string_view` members and updated `operator[]` to be able to return the terminating null.
14621463
* Fixed bugs/issues:
14631464
* [@https://github.com/boostorg/container/issues/323 GitHub #323: ['"flat_tree::try_emplace UB"]].
1465+
* [@https://github.com/boostorg/container/issues/328 GitHub #328: ['"boost::container::deque stores a redundant copy of the allocator, increasing size"]].
14641466

14651467
[endsect]
14661468

include/boost/container/deque.hpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ class deque_base
420420
{ return deque_block_traits<val_alloc_val, options_type::block_bytes, options_type::block_size, stored_size_type>::value; }
421421

422422
typedef deque_value_traits<val_alloc_val> traits_t;
423-
typedef ptr_alloc_t map_allocator_type;
424423

425424
inline val_alloc_ptr prot_allocate_node()
426425
{
@@ -434,12 +433,14 @@ class deque_base
434433

435434
inline ptr_alloc_ptr prot_allocate_map(size_type n)
436435
{
437-
return this->ptr_alloc().allocate(n);
436+
ptr_alloc_t palloc(this->alloc());
437+
return palloc.allocate(n);
438438
}
439439

440440
inline void prot_deallocate_map(ptr_alloc_ptr p, size_type n) BOOST_NOEXCEPT_OR_NOTHROW
441441
{
442-
this->ptr_alloc().deallocate(p, n);
442+
ptr_alloc_t palloc(this->alloc());
443+
return palloc.deallocate(p, n);
443444
}
444445

445446
inline deque_base(size_type num_elements, const allocator_type& a)
@@ -455,8 +456,7 @@ class deque_base
455456
{}
456457

457458
inline explicit deque_base(BOOST_RV_REF(deque_base) x)
458-
: members_( boost::move(x.ptr_alloc())
459-
, boost::move(x.alloc()) )
459+
: members_( boost::move(x.alloc()) )
460460
{}
461461

462462
~deque_base()
@@ -714,26 +714,18 @@ class deque_base
714714

715715
protected:
716716
struct members_holder
717-
: public ptr_alloc_t
718-
, public allocator_type
717+
: public allocator_type
719718
{
720719
friend class deque_base;
721720
members_holder()
722-
: map_allocator_type(), allocator_type()
721+
: allocator_type()
723722
, m_map(), m_map_size()
724723
, m_start_off(), m_finish_off()
725724
{}
726725

727-
explicit members_holder(const allocator_type &a)
728-
: map_allocator_type(a), allocator_type(a)
729-
, m_map(), m_map_size()
730-
, m_start_off(), m_finish_off()
731-
{}
732-
733-
template<class ValAllocConvertible, class PtrAllocConvertible>
734-
members_holder(BOOST_FWD_REF(PtrAllocConvertible) pa, BOOST_FWD_REF(ValAllocConvertible) va)
735-
: map_allocator_type(boost::forward<PtrAllocConvertible>(pa))
736-
, allocator_type (boost::forward<ValAllocConvertible>(va))
726+
template<class ValAllocConvertible>
727+
explicit members_holder(BOOST_FWD_REF(ValAllocConvertible) va)
728+
: allocator_type(boost::forward<ValAllocConvertible>(va))
737729
, m_map(), m_map_size()
738730
, m_start_off(), m_finish_off()
739731
{}
@@ -753,12 +745,6 @@ class deque_base
753745
stored_size_type m_finish_off;
754746
} members_;
755747

756-
inline ptr_alloc_t &ptr_alloc() BOOST_NOEXCEPT_OR_NOTHROW
757-
{ return members_; }
758-
759-
inline const ptr_alloc_t &ptr_alloc() const BOOST_NOEXCEPT_OR_NOTHROW
760-
{ return members_; }
761-
762748
inline allocator_type &alloc() BOOST_NOEXCEPT_OR_NOTHROW
763749
{ return members_; }
764750

@@ -1335,7 +1321,6 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
13351321
this->shrink_to_fit();
13361322
}
13371323
dtl::assign_alloc(this->alloc(), x.alloc(), flag);
1338-
dtl::assign_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
13391324
this->assign(x.cbegin(), x.cend());
13401325
}
13411326
return *this;
@@ -2400,7 +2385,6 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
24002385
this->swap_members(x);
24012386
dtl::bool_<allocator_traits_type::propagate_on_container_swap::value> flag;
24022387
dtl::swap_alloc(this->alloc(), x.alloc(), flag);
2403-
dtl::swap_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
24042388
}
24052389

24062390
//! <b>Effects</b>: Erases all the elements of the deque.
@@ -2504,7 +2488,6 @@ class deque : protected deque_base<typename real_allocator<T, Allocator>::type,
25042488
//Move allocator if needed
25052489
dtl::bool_<allocator_traits_type::propagate_on_container_move_assignment::value> flag;
25062490
dtl::move_alloc(this->alloc(), x.alloc(), flag);
2507-
dtl::move_alloc(this->ptr_alloc(), x.ptr_alloc(), flag);
25082491
//Nothrow swap
25092492
this->swap_members(x);
25102493
}

0 commit comments

Comments
 (0)