Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-02-24 03:59:10


Alberto Barbati <abarbati_at_[hidden]> writes:

> Hi Boosters,
>
> I had a very good time writing iterators with the new iterator_facade
> template. Very good job! It makes writing iterators so much simpler!
>
> What about having a similar template for allocators? Given that a
> large class of useful allocators are de facto built over a couple of
> typeless malloc-like/free-like functions, I imagine something that
> could be used like this:
>
> struct malloc_impl
> {
> static void* allocate(size_t n) { return malloc(n); }
> static void deallocate(void* p) { free(p); }
> };
>
> std::vector<int, boost::allocator_facade<int, malloc_impl> > v;
>
> where boost::allocator_facade<T, malloc_impl> satisfies all
> requirements that std::allocator<T> does.
>
> An implementation for a conforming compiler and library is
> straightforward and allocator_facade could also include workarounds
> for specific platforms where possible (for example it can easily and
> automatically provide the __stl_alloc_rebind hack in STLport).
>
> Is there any interest for such a thing?

My only reservation is that I don't find myself needing to make
allocators very often. In fact, the last time I wanted to make
something with an allocator interface, I found that the standard
interface wasn't appropriate for the project :(. Standard allocators
are really only good for containers, AFAICT.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk