|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r83568 - sandbox/pool2/boost/pool
From: svart.riddare_at_[hidden]
Date: 2013-03-25 17:13:25
Author: edupuis
Date: 2013-03-25 17:13:24 EDT (Mon, 25 Mar 2013)
New Revision: 83568
URL: http://svn.boost.org/trac/boost/changeset/83568
Log:
A pool is itself an allocator. This would be perfect if we didn't need to provide a copy constructor...
Text files modified:
sandbox/pool2/boost/pool/pool.hpp | 32 +++++++++++++++++++++++++++++---
1 files changed, 29 insertions(+), 3 deletions(-)
Modified: sandbox/pool2/boost/pool/pool.hpp
==============================================================================
--- sandbox/pool2/boost/pool/pool.hpp (original)
+++ sandbox/pool2/boost/pool/pool.hpp 2013-03-25 17:13:24 EDT (Mon, 25 Mar 2013)
@@ -96,7 +96,7 @@
*
* -------------------------------------------------------------------------- */
- template<typename T, bool ThreadSafe = false, class Allocator = std::allocator<char>, size_t ExpectedGrowthData = 1, class GrowthDataAllocator = std::allocator<char>>
+template<typename T, bool ThreadSafe = false, class Allocator = std::allocator<char>, size_t ExpectedGrowthData = 1, class GrowthDataAllocator = std::allocator<char>>
class pool;
/* -------------------------------------------------------------------------- */
@@ -104,7 +104,7 @@
/* -------------------------------------------------------------------------- */
template<typename T, bool ThreadSafe, class Allocator, size_t ExpectedGrowthData, class GrowthDataAllocator>
-class pool
+class pool : public std::allocator<T>
{
private :
#include "details/pool.hpp"
@@ -148,10 +148,36 @@
private :
/** ------------------------------------------------------------------------
* Requests a pool buffer, \b without initializing it's content.
- * This private function is used by the various flavors of pool::request().
* ----------------------------------------------------------------------- */
T *request_core(void);
+ /** ------------------------------------------------------------------------
+ * Releases a pool buffer, \b without destroying it's content.
+ * ---------------------------------------------------------------------- */
+ void release_core(T *);
+
+ public :
+ /** ------------------------------------------------------------------------
+ * Requests a pool buffer, \b without initializing it's content.
+ * This function is required for pool to be an allocator.
+ * ----------------------------------------------------------------------- */
+ inline T *allocate(std::allocator<T>::size_type count, const void * = NULL)
+ { assert(count <= _size); return (count <= _size) ? request_core() : NULL; }
+
+ /** ------------------------------------------------------------------------
+ * Releases a pool buffer, \b without destroying it's content.
+ * This function is required for pool to ba an allocator.
+ * ---------------------------------------------------------------------- */
+ inline void deallocate(std::allocator<T>::pointer pointer, std::allocator<T>::size_type count)
+ { assert(count <= _size); if (count <= _size) release_core(pointer); }
+
+ /** ------------------------------------------------------------------------
+ * Returns the maximum size that can be allocated in a single call to
+ * allocate(). This function is required for pool to be an allocator.
+ * ---------------------------------------------------------------------- */
+ inline std::allocator<T>::size_type max_size() const
+ { return _size; }
+
public :
/** ------------------------------------------------------------------------
* Requests and initializes a pool buffer.
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