Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#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)

pool_alloc.txt (1.4 KB ) - added by Armin Felke 14 years ago.
code (readable formatting)

Download all attachments as: .zip

Change History (6)

by Armin Felke, 14 years ago

Attachment: pool_alloc.txt added

code (readable formatting)

comment:1 by Armin Felke, 14 years ago

Sorry for screwing up the code formatting. If unreadable please see the attachment.

comment:2 by anonymous, 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 Chris Newbold, 14 years ago

Milestone: Boost 1.35.1Boost 1.37.0
Owner: changed from No-Maintainer to Chris Newbold
Status: newassigned

comment:4 by Chris Newbold, 14 years ago

Resolution: fixed
Status: assignedclosed

Fixed by changeset #49031 on trunk.

comment:5 by Chris Newbold, 14 years ago

Argh; bad link. Make that [49031/trunk]

Note: See TracTickets for help on using tickets.