Hi,
Isn't that second allocation that of expanding the vector?
Regards,
Johan
"Seweryn Habdank-Wojewódzki"
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
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 \/\/ _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users