$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Seweryn Habdank-Wojewódzki (shw_at_[hidden])
Date: 2007-06-16 17:12:08
HI!
Is there any opportunity, to avoid double allocation of memory using pointer 
containers?
I have simple code (below) and I want allocate memory for objects, construct 
them, and _move_ (transfer) pointer to the container.
Valgrind shows me that there are made 2 alocations even if I am creating only 
1 object.
==20121== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 1)
==20121== malloc/free: in use at exit: 0 bytes in 0 blocks.
==20121== malloc/free: 2 allocs, 2 frees, 8 bytes allocated.
What is happening If the object is huge? Is there any way to transfer the 
pointer?
Regards.
#include <boost/ptr_container/ptr_vector.hpp>
class Foo {
public:
    Foo (int const i) : i_ (i) {}
private:
    int i_;
};
Foo * ret_ptr(int const i) {
    return new Foo(i);
}
int main() {
    boost::ptr_vector<Foo> vfoo;
    for (int i = 0; i < 1; ++i)
        vfoo.push_back (ret_ptr(i));
}
-- |\/\/| Seweryn Habdank-Wojewódzki \/\/