Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54246 - sandbox/monotonic/boost/monotonic/detail
From: christian.schladetsch_at_[hidden]
Date: 2009-06-22 19:38:41


Author: cschladetsch
Date: 2009-06-22 19:38:41 EDT (Mon, 22 Jun 2009)
New Revision: 54246
URL: http://svn.boost.org/trac/boost/changeset/54246

Log:
added trap for null allocation from heap for Pool
Text files modified:
   sandbox/monotonic/boost/monotonic/detail/pool.hpp | 9 +++++----
   1 files changed, 5 insertions(+), 4 deletions(-)

Modified: sandbox/monotonic/boost/monotonic/detail/pool.hpp
==============================================================================
--- sandbox/monotonic/boost/monotonic/detail/pool.hpp (original)
+++ sandbox/monotonic/boost/monotonic/detail/pool.hpp 2009-06-22 19:38:41 EDT (Mon, 22 Jun 2009)
@@ -26,14 +26,14 @@
                                 template <class Storage>
                                 void *allocate(Storage &storage)
                                 {
- if (next == last)
- expand(storage);
+ if (next == last && !expand(storage))
+ return 0;
                                         void *ptr = next;
                                         next += bucket_size;
                                         return ptr;
                                 }
                                 template <class Storage>
- void expand(Storage &storage)
+ bool expand(Storage &storage)
                                 {
                                         size_t capacity = std::max(DefaultSizes::MinPoolSize*bucket_size, (last - first)*bucket_size*2);
                                         void *ptr = storage.from_fixed(capacity, 16);
@@ -41,10 +41,11 @@
                                         {
                                                 ptr = storage.from_heap(capacity, 16);
                                                 if (ptr == 0)
- throw std::bad_alloc("monotonic::pool");
+ return false;
                                         }
                                         first = next = (char *)ptr;
                                         last = first + capacity;
+ return true;
                                 }
                                 void reset()
                                 {


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