Boost logo

Boost :

From: E. Gladyshev (egladysh_at_[hidden])
Date: 2003-08-26 11:33:49


--- Peter Dimov <pdimov_at_[hidden]> wrote:
> E. Gladyshev wrote:
> >
> > I guess my question is that, is boost redefining the
> > memory management concepts that have been established by STL?
>
> Yes and no. The STL uses allocators for containers. Most non-containers do
> not have an allocator parameter, although many standard classes do allocate
> memory.

I agree. It means the STL is not consistent either.

So what are the boost recomendations for using STL containers and boost
in the same class?

I am using STL and trying to use boost in my daily
development. What can I do to implement consistent classes in terms
of memory management. For example, if I need to implement a class A
that has a container and pointer to a data type. I have two options:

template< typename T >
struct A
{
   shared_ptr<T> _data;
   std::list<T> _list;
};

template< typename T, template A = std::allocator<T> >
struct A
{
   shared_ptr<T> _data;
   std::list<T, A> _list;
   A : _data( new T() ) {...}
};

The problem with the first defenition is that I am limiting the built-in STL functionality in
terms of memory management.

The problem with the second definition is that if I expose the allocator template parameter, the
user of my class will expect that all memory allocations of type T are going to be using her
allocator but boost::shared_ptr doesn't support it.

Could you please advise me?

Eugene

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


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