|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r78337 - in sandbox/pool: boost/pool libs/pool/test
From: svart.riddare_at_[hidden]
Date: 2012-05-05 16:29:13
Author: edupuis
Date: 2012-05-05 16:29:12 EDT (Sat, 05 May 2012)
New Revision: 78337
URL: http://svn.boost.org/trac/boost/changeset/78337
Log:
Improved coherency between 'next_size' and 'max_size'; the first one is now always smaller or equal to the second one. No mallocs of more than 'max_size' chunks at once are allowed. Documentation will need update. This fixes #6867.
Added:
sandbox/pool/libs/pool/test/test_bug_6867.cpp (contents, props changed)
Text files modified:
sandbox/pool/boost/pool/pool.hpp | 46 +++++++++++++++------------------------
sandbox/pool/libs/pool/test/test_bug_6701.cpp | 3 --
2 files changed, 18 insertions(+), 31 deletions(-)
Modified: sandbox/pool/boost/pool/pool.hpp
==============================================================================
--- sandbox/pool/boost/pool/pool.hpp (original)
+++ sandbox/pool/boost/pool/pool.hpp 2012-05-05 16:29:12 EDT (Sat, 05 May 2012)
@@ -380,7 +380,7 @@
const size_type nnext_size = 32,
const size_type nmax_size = 0)
:
- list(0, 0), requested_size(nrequested_size), next_size(nnext_size), start_size(nnext_size),max_size(nmax_size)
+ list(0, 0), requested_size(nrequested_size), next_size(nnext_size), start_size(nnext_size), max_size(nmax_size)
{ //! Constructs a new empty Pool that can be used to allocate chunks of size RequestedSize.
//! \param nrequested_size Requested chunk size
//! \param nnext_size parameter is of type size_type,
@@ -388,8 +388,7 @@
//! the first time that object needs to allocate system memory.
//! The default is 32. This parameter may not be 0.
//! \param nmax_size is the maximum number of chunks to allocate in one block.
- set_next_size(nnext_size);
- set_max_size(nmax_size);
+ set_max_size(nmax_size);
}
~pool()
@@ -414,7 +413,8 @@
void set_next_size(const size_type nnext_size)
{ //! Set number of chunks to request from the system the next time that object needs to allocate system memory. This value should never be set to 0.
BOOST_USING_STD_MIN();
- next_size = start_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nnext_size, max_chunks());
+ next_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nnext_size, max_size);
+ BOOST_ASSERT(next_size > 0);
}
size_type get_max_size() const
{ //! \returns max_size.
@@ -423,7 +423,9 @@
void set_max_size(const size_type nmax_size)
{ //! Set max_size.
BOOST_USING_STD_MIN();
- max_size = min BOOST_PREVENT_MACRO_SUBSTITUTION(nmax_size, max_chunks());
+ max_size = nmax_size ? min BOOST_PREVENT_MACRO_SUBSTITUTION(nmax_size, max_chunks()) : max_chunks();
+
+ set_next_size(next_size);
}
size_type get_requested_size() const
{ //! \returns the requested size passed into the constructor.
@@ -663,7 +665,7 @@
ptr = next;
}
- next_size = start_size;
+ set_next_size(start_size);
return ret;
}
@@ -695,8 +697,8 @@
list.invalidate();
this->first = 0;
- next_size = start_size;
-
+
+ set_next_size(start_size);
return true;
}
@@ -722,15 +724,11 @@
if(ptr == 0)
return 0;
}
- const details::PODptr<size_type> node(ptr, POD_size);
-
- BOOST_USING_STD_MIN();
- if(!max_size)
- set_next_size(next_size << 1);
- else if(next_size < max_size * requested_size / partition_size)
- set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
+
+ set_next_size(next_size << 1);
// initialize it,
+ const details::PODptr<size_type> node(ptr, POD_size);
store().add_block(node.begin(), node.element_size(), partition_size);
// insert it into the list,
@@ -762,18 +760,14 @@
if(ptr == 0)
return 0;
}
- const details::PODptr<size_type> node(ptr, POD_size);
-
- BOOST_USING_STD_MIN();
- if(!max_size)
- set_next_size(next_size << 1);
- else if(next_size < max_size * requested_size / partition_size)
- set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
+
+ set_next_size(next_size << 1);
// initialize it,
// (we can use "add_block" here because we know that
// the free list is empty, so we don't have to use
// the slower ordered version)
+ const details::PODptr<size_type> node(ptr, POD_size);
store().add_ordered_block(node.begin(), node.element_size(), partition_size);
// insert it into the list,
@@ -810,7 +804,7 @@
{ //! Gets address of a chunk n, allocating new memory if not already available.
//! \returns Address of chunk n if allocated ok.
//! \returns 0 if not enough memory for n chunks.
- if (n > max_chunks())
+ if (n > max_size)
return 0;
const size_type partition_size = alloc_size();
@@ -858,11 +852,7 @@
store().add_ordered_block(node.begin() + num_chunks * partition_size,
node.element_size() - num_chunks * partition_size, partition_size);
- BOOST_USING_STD_MIN();
- if(!max_size)
- set_next_size(next_size << 1);
- else if(next_size < max_size * requested_size / partition_size)
- set_next_size(min BOOST_PREVENT_MACRO_SUBSTITUTION(next_size << 1, max_size * requested_size / partition_size));
+ set_next_size(next_size << 1);
// insert it into the list,
// handle border case.
Modified: sandbox/pool/libs/pool/test/test_bug_6701.cpp
==============================================================================
--- sandbox/pool/libs/pool/test/test_bug_6701.cpp (original)
+++ sandbox/pool/libs/pool/test/test_bug_6701.cpp 2012-05-05 16:29:12 EDT (Sat, 05 May 2012)
@@ -17,9 +17,6 @@
void *x = p.malloc();
BOOST_ASSERT(!x);
- BOOST_ASSERT(std::numeric_limits<size_t>::max() / 1024 >= p.get_next_size());
- BOOST_ASSERT(std::numeric_limits<size_t>::max() / 1024 >= p.get_max_size());
-
void *y = p.ordered_malloc(std::numeric_limits<size_t>::max() / 768);
BOOST_ASSERT(!y);
Added: sandbox/pool/libs/pool/test/test_bug_6867.cpp
==============================================================================
--- (empty file)
+++ sandbox/pool/libs/pool/test/test_bug_6867.cpp 2012-05-05 16:29:12 EDT (Sat, 05 May 2012)
@@ -0,0 +1,23 @@
+/* Copyright (C) 2012 Étienne Dupuis
+*
+* Use, modification and distribution is subject to the
+* Boost Software License, Version 1.0. (See accompanying
+* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+*/
+
+// Test of bug #6867 (https://svn.boost.org/trac/boost/ticket/6867)
+
+#include <boost/pool/object_pool.hpp>
+
+int main()
+{
+ boost::pool<> p(sizeof(int), 16, 16);
+ void *ptr = p.ordered_malloc(32);
+
+ BOOST_ASSERT(!ptr);
+
+ p.set_max_size(4);
+ BOOST_ASSERT(p.get_next_size() <= 4);
+
+ return 0;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk