Simplify array_allocator; update documentation

This commit is contained in:
Glen Fernandes
2014-02-12 19:19:02 -08:00
parent 3d279e6c6d
commit d9333e5375
3 changed files with 18 additions and 18 deletions

View File

@@ -103,14 +103,14 @@ namespace boost {
object(0) {
}
template<class U>
as_allocator(const as_allocator& other, U* memory)
as_allocator(const as_allocator& other, void* memory,
std::size_t offset)
: as_size_base<T, A>(other) {
enum {
M = boost::alignment_of<type>::value
};
std::size_t n1 = sizeof(U) + M - 1;
char* p1 = reinterpret_cast<char*>(memory) + n1;
std::size_t n1 = offset + M - 1;
char* p1 = static_cast<char*>(memory) + n1;
while (std::size_t(p1) % M != 0) {
p1--;
}
@@ -138,11 +138,11 @@ namespace boost {
return ya.max_size();
}
pointer allocate(size_type, const void* value = 0) {
pointer allocate(size_type count, const void* value = 0) {
enum {
M = boost::alignment_of<type>::value
};
std::size_t n1 = sizeof(value_type) + M - 1;
std::size_t n1 = count * sizeof(value_type) + M - 1;
std::size_t n2 = size * sizeof(type);
CA ca(*this);
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
@@ -153,11 +153,11 @@ namespace boost {
return static_cast<value_type*>(p1);
}
void deallocate(pointer memory, size_type) {
void deallocate(pointer memory, size_type count) {
enum {
M = boost::alignment_of<type>::value
};
std::size_t n1 = sizeof(value_type) + M - 1;
std::size_t n1 = count * sizeof(value_type) + M - 1;
char* p1 = reinterpret_cast<char*>(memory);
CA ca(*this);
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
@@ -172,7 +172,6 @@ namespace boost {
YA ya(*this);
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
YT::construct(ya, memory, value);
#else
ya.construct(memory, value);
#endif
@@ -287,14 +286,14 @@ namespace boost {
object(0) {
}
template<class U>
ms_allocator(const ms_allocator& other, U* memory)
ms_allocator(const ms_allocator& other, void* memory,
std::size_t offset)
: ms_size_base<T>(other) {
enum {
M = boost::alignment_of<type>::value
};
std::size_t n1 = sizeof(U) + M - 1;
char* p1 = reinterpret_cast<char*>(memory) + n1;
std::size_t n1 = offset + M - 1;
char* p1 = static_cast<char*>(memory) + n1;
while (std::size_t(p1) % M != 0) {
p1--;
}
@@ -322,11 +321,11 @@ namespace boost {
return N;
}
pointer allocate(size_type, const void* = 0) {
pointer allocate(size_type count, const void* = 0) {
enum {
M = boost::alignment_of<type>::value
};
std::size_t n1 = sizeof(value_type) + M - 1;
std::size_t n1 = count * sizeof(value_type) + M - 1;
std::size_t n2 = size * sizeof(type);
void* p1 = ::operator new(n1 + n2);
return static_cast<value_type*>(p1);

View File

@@ -21,7 +21,7 @@ namespace boost {
typedef sp_counted_impl_pda<P, D, A> Y;
public:
sp_counted_impl_pda(P, const D&, const A& allocator_)
: allocator(allocator_, this) {
: allocator(allocator_, this, sizeof(Y)) {
}
virtual void dispose() {

View File

@@ -252,8 +252,9 @@ boost::shared_ptr&lt;int[4][2]&gt; a2 = boost::make_shared_noinit&lt;int[4][2]&g
<h2><a name="history">History</a></h2>
<p>February 2014. Glen Fernandes updated overloads of make_shared and
allocate_shared to conform to the specification in C++ standard paper
<a href="#N3870">N3870</a> including resolving C++ standard library
defect report 2070.</p>
<a href="#N3870">N3870</a>, including resolving C++ standard library
defect report 2070, and reduced the spatial overhead of the internal
bookkeeping structures.</p>
<p>November 2012. Glen Fernandes contributed implementations of
make_shared and allocate_shared for arrays.</p>
<h2><a name="references">References</a></h2>