Subject: Re: [Boost-bugs] [Boost C++ Libraries] #11312: smart_ptr::detail::as_allocator::allocate() adds alignment padding when it's not needed
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-05-16 00:31:47
#11312: smart_ptr::detail::as_allocator::allocate() adds alignment padding when
it's not needed
----------------------------------+-----------------------
Reporter: David Aue <david@â¦> | Owner: glenfe
Type: Bugs | Status: new
Milestone: To Be Determined | Component: smart_ptr
Version: Boost 1.57.0 | Severity: Problem
Resolution: | Keywords:
----------------------------------+-----------------------
Comment (by David Aue <david@â¦>):
{{{
pointer allocate(size_type count, const_void_pointer = 0) {
enum {
M = boost::alignment_of<type>::value
};
std::size_t n1 = count * sizeof(value_type);
std::size_t n2 = data.size * sizeof(type);
std::size_t n3 = n2 + M;
CA ca(allocator());
void* p1 = ca.allocate(n1 + n3);
void* p2 = static_cast<char*>(p1) + n1;
(void)boost::alignment::align(M, n2, p2, n3);
*data.result = static_cast<type*>(p2);
return static_cast<value_type*>(p1);
}
I call:
boost::allocate_shared<int[]>(allocator, 4);
Inside allocate() I see this:
n1 == 20 for ms_init_tag
n2 == 16 for the 4 ints
M == 4
n3 == 20
ca.allocate is called with n1+n3 for a total of 40 bytes.
p1 == some_address
p2 == some_address + n1
boost::alignment::align called to fix p2 for 4 byte alignment
p2 is unchanged by align
So we allocated 40 bytes and we are using the first 20 for ms_init and the
next 16 for the int[4] and then there are 4 unused bytes that are not
affecting our 4 byte alignment requirement.
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11312#comment:3> 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:18 UTC