#1996 closed Patches (fixed)
"void" template specialisation for the pool allocators
Reported by: | Armin Felke | Owned by: | Chris Newbold |
---|---|---|---|
Milestone: | Boost 1.37.0 | Component: | pool |
Version: | Boost 1.35.0 | Severity: | Optimization |
Keywords: | Cc: |
Description
It might be reasonable to add a template specialisation for the allocator classes "pool_allocator<T,..>" and "fast_pool_allocator<T,..>" with T=void?
The library boost::multi_index, e.g., currently (version 1.35.0) uses the allocator<void> notation in its generic code (expecting a "default allocator").
In section 20.4.1 [lib.default.allocator] of the C++ standard the following specialisation is defined for class std::allocator as follows:
<code> template <class T> class allocator; specialize for void: template <> class allocator<void> { public:
typedef void* pointer; typedef const void* const_pointer; reference-to-void members are impossible. typedef void value_type; template <class U> struct rebind { typedef allocator<U> other; };
}; </code>
In order to use the pool allocators with multi_index_container and ease generic programming, I would suggest the following additions to pool_alloc.hpp:
<code>
template<
typename UserAllocator, typename Mutex, unsigned NextSize>
class pool_allocator<void, UserAllocator, Mutex, NextSize> { public:
typedef void* pointer; typedef const void* const_pointer; typedef void value_type; template <class U> struct rebind {
typedef pool_allocator<U, UserAllocator, Mutex, NextSize> other;
};
};
template<
typename UserAllocator, typename Mutex, unsigned NextSize>
class fast_pool_allocator<void, UserAllocator, Mutex, NextSize> { public:
typedef void* pointer; typedef const void* const_pointer; typedef void value_type; template <class U> struct rebind {
typedef fast_pool_allocator<U, UserAllocator, Mutex, NextSize> other;
};
};
</code>
Best regards Armin Felke
Attachments (1)
Change History (6)
by , 14 years ago
Attachment: | pool_alloc.txt added |
---|
comment:1 by , 14 years ago
Sorry for screwing up the code formatting. If unreadable please see the attachment.
comment:2 by , 14 years ago
It's useful. In my current project,I hope to use pool allocators for the boost function for optimizing,but I found the T can't be void.
comment:3 by , 14 years ago
Milestone: | Boost 1.35.1 → Boost 1.37.0 |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:4 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixed by changeset #49031 on trunk.
code (readable formatting)