Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78284 - in sandbox/pool: boost/pool libs/pool/test
From: svart.riddare_at_[hidden]
Date: 2012-04-30 15:52:24


Author: edupuis
Date: 2012-04-30 15:52:22 EDT (Mon, 30 Apr 2012)
New Revision: 78284
URL: http://svn.boost.org/trac/boost/changeset/78284

Log:
GCC compilation and cleaned up tabs/spaces.
Text files modified:
   sandbox/pool/boost/pool/object_pool.hpp | 36 ++++--
   sandbox/pool/boost/pool/static_pool.hpp | 85 ++++++++-------
   sandbox/pool/libs/pool/test/test_static_pool.cpp | 216 ++++++++++++++++++++--------------------
   3 files changed, 177 insertions(+), 160 deletions(-)

Modified: sandbox/pool/boost/pool/object_pool.hpp
==============================================================================
--- sandbox/pool/boost/pool/object_pool.hpp (original)
+++ sandbox/pool/boost/pool/object_pool.hpp 2012-04-30 15:52:22 EDT (Mon, 30 Apr 2012)
@@ -63,7 +63,7 @@
 { //!
   public:
     typedef T element_type; //!< ElementType
- typedef typename Pool::user_allocator user_allocator; //!<
+ typedef typename Pool::user_allocator user_allocator; //!<
     typedef typename Pool::size_type size_type; //!< pool<UserAllocator>::size_type
     typedef typename Pool::difference_type difference_type; //!< pool<UserAllocator>::difference_type
 
@@ -86,7 +86,7 @@
     }
 
   public:
- explicit object_pool_base(const size_type arg_requested_objects)
+ explicit object_pool_base(const size_type arg_requested_objects)
     :
     Pool(sizeof(T), arg_requested_objects)
     { //! Constructs a new (empty by default) ObjectPoolBase.
@@ -286,7 +286,13 @@
 template<typename T, typename UserAllocator>
 class object_pool : public object_pool_base<T, pool<UserAllocator> >
 {
- public:
+ public:
+ typedef typename object_pool_base<T, pool<UserAllocator> >::element_type element_type; //!< ElementType
+ typedef typename object_pool_base<T, pool<UserAllocator> >::user_allocator user_allocator; //!<
+ typedef typename object_pool_base<T, pool<UserAllocator> >::size_type size_type; //!< pool<UserAllocator>::size_type
+ typedef typename object_pool_base<T, pool<UserAllocator> >::difference_type difference_type; //!< pool<UserAllocator>::difference_type
+
+ public:
     explicit object_pool(const size_type arg_next_size = 32, const size_type arg_max_size = 0)
     :
     object_pool_base<T, pool<UserAllocator> >(arg_next_size)
@@ -295,13 +301,13 @@
       //! \pre next_size != 0.
       //! \param arg_max_size Maximum number of chunks to ever request from the system - this puts a cap on the doubling algorithm
       //! used by the underlying pool.
- set_max_size(arg_max_size);
+ set_max_size(arg_max_size);
     }
 
- public:
+ public:
     size_type get_next_size() const
     { //! \returns The number of chunks that will be allocated next time we run out of memory.
- return pool<UserAllocator>::get_next_size();
+ return pool<UserAllocator>::get_next_size();
     }
 
     void set_next_size(const size_type nnext_size)
@@ -310,14 +316,14 @@
       pool<UserAllocator>::set_next_size(nnext_size);
     }
 
- size_type get_max_size() const
+ size_type get_max_size() const
     { //! \returns max_size.
- return pool<UserAllocator>::get_max_size();
+ return pool<UserAllocator>::get_max_size();
     }
 
     void set_max_size(const size_type nmax_size)
     { //! Set max_size.
- pool<UserAllocator>::set_max_size(nmax_size);
+ pool<UserAllocator>::set_max_size(nmax_size);
     }
 };
 
@@ -347,13 +353,19 @@
 template<typename T, typename UserAllocator>
 class static_object_pool : public object_pool_base<T, static_pool<UserAllocator> >
 {
- public:
- explicit static_object_pool(const size_type arg_requested_objects)
+ public:
+ typedef typename object_pool_base<T, static_pool<UserAllocator> >::element_type element_type; //!< ElementType
+ typedef typename object_pool_base<T, static_pool<UserAllocator> >::user_allocator user_allocator; //!<
+ typedef typename object_pool_base<T, static_pool<UserAllocator> >::size_type size_type; //!< pool<UserAllocator>::size_type
+ typedef typename object_pool_base<T, static_pool<UserAllocator> >::difference_type difference_type; //!< pool<UserAllocator>::difference_type
+
+ public:
+ explicit static_object_pool(const size_type arg_requested_objects)
     :
     object_pool_base<T, static_pool<UserAllocator> >(arg_requested_objects)
     { //! Constructs a new (empty by default) StaticObjectPool.
       //! \param arg_requested_objects Number of memory chunks to allocate at initialization.
- //! It defines the maximum number of objects that can be malloc'ed from this pool.
+ //! It defines the maximum number of objects that can be malloc'ed from this pool.
     }
 };
 

Modified: sandbox/pool/boost/pool/static_pool.hpp
==============================================================================
--- sandbox/pool/boost/pool/static_pool.hpp (original)
+++ sandbox/pool/boost/pool/static_pool.hpp 2012-04-30 15:52:22 EDT (Mon, 30 Apr 2012)
@@ -29,64 +29,69 @@
 template<typename UserAllocator>
 class static_pool: protected pool<UserAllocator>
 {
+ public :
+ typedef typename pool<UserAllocator>::user_allocator user_allocator;
+ typedef typename UserAllocator::size_type size_type;
+ typedef typename UserAllocator::difference_type difference_type;
+
   public: // Overridden functions
- explicit static_pool(const size_type nrequested_size, const size_t nrequested_items)
- :
- pool<UserAllocator>(nrequested_size, nrequested_items)
+ explicit static_pool(const size_type nrequested_size, const size_type nrequested_items)
+ :
+ pool<UserAllocator>(nrequested_size, nrequested_items)
     {
- free BOOST_PREVENT_MACRO_SUBSTITUTION(pool<UserAllocator>::malloc BOOST_PREVENT_MACRO_SUBSTITUTION());
- }
+ free BOOST_PREVENT_MACRO_SUBSTITUTION(pool<UserAllocator>::malloc BOOST_PREVENT_MACRO_SUBSTITUTION());
+ }
 
     void * malloc BOOST_PREVENT_MACRO_SUBSTITUTION()
- {
- return store().empty() ? NULL : store().malloc BOOST_PREVENT_MACRO_SUBSTITUTION();
- }
-
- void * ordered_malloc()
- {
- return store().empty() ? NULL : store().malloc BOOST_PREVENT_MACRO_SUBSTITUTION();
- }
-
- void * ordered_malloc(size_type n)
- {
- const size_type partition_size = alloc_size();
- const size_type total_req_size = n * requested_size;
- const size_type num_chunks = total_req_size / partition_size +
- ((total_req_size % partition_size) ? true : false);
+ {
+ return this->store().empty() ? NULL : this->store().malloc BOOST_PREVENT_MACRO_SUBSTITUTION();
+ }
+
+ void * ordered_malloc()
+ {
+ return this->store().empty() ? NULL : this->store().malloc BOOST_PREVENT_MACRO_SUBSTITUTION();
+ }
 
- return store().malloc_n(num_chunks, partition_size);
- }
+ void * ordered_malloc(size_type n)
+ {
+ const size_type partition_size = this->alloc_size();
+ const size_type total_req_size = n * this->requested_size;
+ const size_type num_chunks = total_req_size / partition_size +
+ ((total_req_size % partition_size) ? true : false);
+
+ return this->store().malloc_n(num_chunks, partition_size);
+ }
 
   public: // Inherited functions
- void free BOOST_PREVENT_MACRO_SUBSTITUTION(void * const chunk)
- {
- return pool<UserAllocator>::free BOOST_PREVENT_MACRO_SUBSTITUTION(chunk);
- }
-
- void ordered_free(void * const chunk)
- {
- return pool<UserAllocator>::ordered_free(chunk);
- }
+ void free BOOST_PREVENT_MACRO_SUBSTITUTION(void * const chunk)
+ {
+ return pool<UserAllocator>::free BOOST_PREVENT_MACRO_SUBSTITUTION(chunk);
+ }
+
+ void ordered_free(void * const chunk)
+ {
+ return pool<UserAllocator>::ordered_free(chunk);
+ }
 
- void free BOOST_PREVENT_MACRO_SUBSTITUTION(void * const chunks, const size_type n)
+ void free BOOST_PREVENT_MACRO_SUBSTITUTION(void * const chunks, const size_type n)
     {
- return pool<UserAllocator>::free BOOST_PREVENT_MACRO_SUBSTITUTION(chunks, n);
+ return pool<UserAllocator>::free BOOST_PREVENT_MACRO_SUBSTITUTION(chunks, n);
     }
 
     void ordered_free(void * const chunks, const size_type n)
- {
- return pool<UserAllocator>::ordered_free(chunks, n);
- }
+ {
+ return pool<UserAllocator>::ordered_free(chunks, n);
+ }
 
     size_type get_requested_size() const
     {
- return pool<UserAllocator>::get_requested_size();
- }
+ return pool<UserAllocator>::get_requested_size();
+ }
        
     bool is_from(void * const chunk) const
     {
- return pool<UserAllocator>::is_from(chunk);
- }
+ return pool<UserAllocator>::is_from(chunk);
+ }
 };
 
 } // namespace boost

Modified: sandbox/pool/libs/pool/test/test_static_pool.cpp
==============================================================================
--- sandbox/pool/libs/pool/test/test_static_pool.cpp (original)
+++ sandbox/pool/libs/pool/test/test_static_pool.cpp 2012-04-30 15:52:22 EDT (Mon, 30 Apr 2012)
@@ -20,8 +20,8 @@
 
   static char * malloc BOOST_PREVENT_MACRO_SUBSTITUTION(const size_type bytes)
   {
- BOOST_TEST(reset);
- reset = false;
+ BOOST_TEST(reset);
+ reset = false;
 
     return new (std::nothrow) char[bytes];
   }
@@ -31,7 +31,7 @@
     delete [] block;
   }
 
- static bool reset;
+ static bool reset;
 };
 
 bool user_allocator_once::reset = false;
@@ -40,10 +40,10 @@
 
 class Count
 {
- public :
- static int count;
- Count() { count += 1; }
- ~Count() { count -= 1; }
+ public :
+ static int count;
+ Count() { count += 1; }
+ ~Count() { count -= 1; }
 };
 
 int Count::count = 0;
@@ -53,76 +53,76 @@
 template<int SIZE>
 void test_static_pool()
 {
- static const int pool_size = 24; // Initial size of pool
- static const int num_iterations = pool_size + 8; // Number of mallocs we will try on pool in following tests
- static const int num_random_iterations = 2000; // Number of iterations for test #4 that follows
- static const int consecutive_elements = 5; // Number of consecutive elements we will request
-
- void *p[num_iterations];
-
- user_allocator_once::reset = true;
- boost::static_pool<user_allocator_once> pool(SIZE, pool_size);
-
- for (int n = 0; n < 2; n++)
- {
- // TEST #1
- for (int k = 0; k < num_iterations; k++)
- {
- p[k] = pool.malloc();
- BOOST_TEST((p[k] != NULL) == (k < pool_size));
- }
-
- for (int k = 0; k < num_iterations; k++)
- BOOST_ASSERT(!p[k] || pool.is_from(p[k]));
-
- for (int k = 0; k < num_iterations; k++)
- p[k] ? pool.ordered_free(p[k]) : (void)(0);
-
- // TEST #2
- for (int k = 0; k < num_iterations; k++)
- {
- p[k] = pool.ordered_malloc(consecutive_elements);
- BOOST_TEST((p[k] != NULL) == (k < pool_size / consecutive_elements));
- }
-
- for (int k = 0; k < num_iterations; k++)
- p[k] ? pool.ordered_free(p[k], consecutive_elements) : (void)(0);
-
- // TEST #3
- for (int k = 0; k < num_iterations; k++)
- {
- p[k] = pool.malloc();
- BOOST_TEST((p[k] != NULL) == (k < pool_size));
- }
-
- for (int k = 0; k < num_iterations; k++)
- p[k] ? pool.free(p[k]) : (void)(0);
-
- // TEST #4
-
- srand(NULL);
-
- int allocated = 0;
- for (int k = 0; k < pool_size / 2; k++)
- p[allocated++] = pool.malloc();
-
- for (int k = 0; k < num_random_iterations; k++)
- {
- if ((rand() & 8) && (allocated < pool_size))
- {
- p[allocated++] = pool.malloc();
- }
- else if (allocated > 0)
- {
- void *_p = p[--allocated];
- BOOST_TEST(_p && pool.is_from(_p));
- pool.free(_p);
- }
- }
-
- while (allocated > 0)
- pool.free(p[--allocated]);
- }
+ static const int pool_size = 24; // Initial size of pool
+ static const int num_iterations = pool_size + 8; // Number of mallocs we will try on pool in following tests
+ static const int num_random_iterations = 2000; // Number of iterations for test #4 that follows
+ static const int consecutive_elements = 5; // Number of consecutive elements we will request
+
+ void *p[num_iterations];
+
+ user_allocator_once::reset = true;
+ boost::static_pool<user_allocator_once> pool(SIZE, pool_size);
+
+ for (int n = 0; n < 2; n++)
+ {
+ // TEST #1
+ for (int k = 0; k < num_iterations; k++)
+ {
+ p[k] = pool.malloc();
+ BOOST_TEST((p[k] != NULL) == (k < pool_size));
+ }
+
+ for (int k = 0; k < num_iterations; k++)
+ BOOST_ASSERT(!p[k] || pool.is_from(p[k]));
+
+ for (int k = 0; k < num_iterations; k++)
+ p[k] ? pool.ordered_free(p[k]) : (void)(0);
+
+ // TEST #2
+ for (int k = 0; k < num_iterations; k++)
+ {
+ p[k] = pool.ordered_malloc(consecutive_elements);
+ BOOST_TEST((p[k] != NULL) == (k < pool_size / consecutive_elements));
+ }
+
+ for (int k = 0; k < num_iterations; k++)
+ p[k] ? pool.ordered_free(p[k], consecutive_elements) : (void)(0);
+
+ // TEST #3
+ for (int k = 0; k < num_iterations; k++)
+ {
+ p[k] = pool.malloc();
+ BOOST_TEST((p[k] != NULL) == (k < pool_size));
+ }
+
+ for (int k = 0; k < num_iterations; k++)
+ p[k] ? pool.free(p[k]) : (void)(0);
+
+ // TEST #4
+
+ srand(0);
+
+ int allocated = 0;
+ for (int k = 0; k < pool_size / 2; k++)
+ p[allocated++] = pool.malloc();
+
+ for (int k = 0; k < num_random_iterations; k++)
+ {
+ if ((rand() & 8) && (allocated < pool_size))
+ {
+ p[allocated++] = pool.malloc();
+ }
+ else if (allocated > 0)
+ {
+ void *_p = p[--allocated];
+ BOOST_TEST(_p && pool.is_from(_p));
+ pool.free(_p);
+ }
+ }
+
+ while (allocated > 0)
+ pool.free(p[--allocated]);
+ }
 }
 
 // Testing static_object_pool
@@ -130,47 +130,47 @@
 template<typename T>
 void test_static_object_pool()
 {
- static const int pool_size = 24; // Initial size of pool
- static const int num_random_iterations = 200; // Number of iterations f
+ static const int pool_size = 24; // Initial size of pool
+ static const int num_random_iterations = 200; // Number of iterations f
 
- user_allocator_once::reset = true;
- boost::static_object_pool<T, user_allocator_once> pool(pool_size);
+ user_allocator_once::reset = true;
+ boost::static_object_pool<T, user_allocator_once> pool(pool_size);
 
- T *p[pool_size];
+ T *p[pool_size];
 
- // TEST #1
-
- srand(NULL);
-
- int allocated = 0;
- for (int k = 0; k < pool_size / 2; k++)
- p[allocated++] = pool.construct();
-
- for (int k = 0; k < num_random_iterations; k++)
- {
- if ((rand() & 8) && (allocated < pool_size))
- {
- p[allocated++] = pool.construct();
- }
- else if (allocated > 0)
- {
- pool.destroy(p[--allocated]);
- }
+ // TEST #1
 
- BOOST_TEST(Count::count == allocated);
- }
+ srand(0);
+
+ int allocated = 0;
+ for (int k = 0; k < pool_size / 2; k++)
+ p[allocated++] = pool.construct();
+
+ for (int k = 0; k < num_random_iterations; k++)
+ {
+ if ((rand() & 8) && (allocated < pool_size))
+ {
+ p[allocated++] = pool.construct();
+ }
+ else if (allocated > 0)
+ {
+ pool.destroy(p[--allocated]);
+ }
+
+ BOOST_TEST(Count::count == allocated);
+ }
 
- while (allocated < pool_size / 4)
- p[allocated++] = pool.construct();
+ while (allocated < pool_size / 4)
+ p[allocated++] = pool.construct();
 }
 
 // Main
 
 int main()
 {
- test_static_pool<8>();
- test_static_object_pool<Count>();
- BOOST_TEST(Count::count == 0);
+ test_static_pool<8>();
+ test_static_object_pool<Count>();
+ BOOST_TEST(Count::count == 0);
 
- return 0;
+ 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