Hi,
I have an heterogeneous container holding pointers to objects of type B. I
want to insert objects of type D1,D2,... that derive from B, and I want to do
that using a custom stl like allocator, for example:
B* obj = my_alloc<D>::allocate(1);
obj = new (obj) B();
container.insert(obj);
My problem is that when an object is removed from the container, I have to
explicitely deallocate it from my allocator, but the static info was lost, so
I cannot do
my_alloc>::deallocate(1,oj);
I've asked in boost irc channel, and someone told me ptr_* boost libraries
solve this problem, is this correct?
thanks
--
Marco Correia
On 4/1/06, Marco Correia
B* obj = my_alloc<D>::allocate(1); obj = new (obj) B(); container.insert(obj);
My problem is that when an object is removed from the container, I have to explicitely deallocate it from my allocator, but the static info was lost, so I cannot do
my_alloc>::deallocate(1,oj);
Just to point out, you probably want to use your allocator's construct and destroy methods too.
I've asked in boost irc channel, and someone told me ptr_* boost libraries solve this problem, is this correct?
I don't think that the ptr_ ones will, but shared_ptr allows you to specify a custom deleter at construction, which seems to be to be just what you need. ~ Scott
On 4/1/06, Marco Correia
wrote: B* obj = my_alloc<D>::allocate(1); obj = new (obj) B(); container.insert(obj);
My problem is that when an object is removed from the container, I have to explicitely deallocate it from my allocator, but the static info was lost, so I cannot do
my_alloc>::dealloc I've asked in boost irc channel, and someone told me ptr_* boost
me22 wrote: libraries
solve this problem, is this correct?
I don't think that the ptr_ ones will, but shared_ptr allows you to specify a custom deleter at construction, which seems to be to be just what you need.
Well, if you need to keep the exact type around, you can use typeid(). But you need that both with shared_ptr and ptr_vector. With ptr_vector, you can plug your allocator into new_clone() and delete_clone(). -Thorsten
Hi, Thanks for the ideas, however I do not understand how typeid may be used to solve this. How do I instantiate my deallocator with information that comes from typeid? thanks again Marco On Monday 03 April 2006 14:41, Thorsten Ottosen wrote:
me22 wrote:
On 4/1/06, Marco Correia
wrote: B* obj = my_alloc<D>::allocate(1); obj = new (obj) B(); container.insert(obj);
My problem is that when an object is removed from the container, I
have to
explicitely deallocate it from my allocator, but the static info was
lost, so
I cannot do
my_alloc>::dealloc I've asked in boost irc channel, and someone told me ptr_* boost
libraries
solve this problem, is this correct?
I don't think that the ptr_ ones will, but shared_ptr allows you to specify a custom deleter at construction, which seems to be to be just what you need.
Well, if you need to keep the exact type around, you can use typeid(). But you need that both with shared_ptr and ptr_vector.
With ptr_vector, you can plug your allocator into new_clone() and delete_clone().
-Thorsten
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
--
Marco Correia
Marco Correia wrote:
Hi,
Thanks for the ideas, however I do not understand how typeid may be used to solve this. How do I instantiate my deallocator with information that comes from typeid?
Well, you can use typeid() to figure out the type of the object. I don't know why you loose the type information, but it's your job to find it again, no matter what approach you use. I can't comment more specific with the infor you gave. -Thorsten
participants (3)
-
Marco Correia
-
me22
-
Thorsten Ottosen