Christoph Heindl
2013-02-14 07:38:40 UTC
Hi,
I was using the Cpp ZMQ interface lately and while writing a bunch of unit
tests I came accross curious behaviour in the move constructor and
assignment operator of zmq::message_t.
The following tests fail (zmq 3.2.2, latest zmq.hpp from github, MSVC10)
zmq::message_t m0(10);
void *adr = m0.data();
zmq::message_t m1;
m1 = std::move(m0);
BOOST_REQUIRE_EQUAL(adr, m1.data());
It might be a semantic error on my side, but I would have thought that an
efficient implementation would happly reuse the buffer allocated by m0.
Instead i get a different buffer address. Similarily the move constructor
seems to re(a)locate the buffer
zmq::message_t m0(10);
void *adr = m0.data();
zmq::message_t m1(std::move(m0));
BOOST_REQUIRE_EQUAL(adr, m1.data())
Is this behaviour intended?
Btw. in zmq.hpp std::swap is used in the move assignment operator. This
seems to me as both buffers survive (at least temporarily) in a scenario as
described above ( zmq::message_t m1(std::move(m0))). I guess that has
something todo with the fact that closing the message is always done in the
destructor.
Best,
Christoph
I was using the Cpp ZMQ interface lately and while writing a bunch of unit
tests I came accross curious behaviour in the move constructor and
assignment operator of zmq::message_t.
The following tests fail (zmq 3.2.2, latest zmq.hpp from github, MSVC10)
zmq::message_t m0(10);
void *adr = m0.data();
zmq::message_t m1;
m1 = std::move(m0);
BOOST_REQUIRE_EQUAL(adr, m1.data());
It might be a semantic error on my side, but I would have thought that an
efficient implementation would happly reuse the buffer allocated by m0.
Instead i get a different buffer address. Similarily the move constructor
seems to re(a)locate the buffer
zmq::message_t m0(10);
void *adr = m0.data();
zmq::message_t m1(std::move(m0));
BOOST_REQUIRE_EQUAL(adr, m1.data())
Is this behaviour intended?
Btw. in zmq.hpp std::swap is used in the move assignment operator. This
seems to me as both buffers survive (at least temporarily) in a scenario as
described above ( zmq::message_t m1(std::move(m0))). I guess that has
something todo with the fact that closing the message is always done in the
destructor.
Best,
Christoph