Boost logo

Boost Users :

From: Johan 't Hart (jopie64_at_[hidden])
Date: 2007-06-16 19:11:16


Hi,

Isn't that second allocation that of expanding the vector?

Regards,
Johan

"Seweryn Habdank-Wojewódzki" <shw_at_[hidden]> schreef in bericht
news:200706162312.09141.shw_at_agh.edu.pl...
> 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
> \/\/
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net