[zeromq-dev] C++ Move Constructor and Assignment Operator

Richard_Newton at waters.com Richard_Newton at waters.com
Thu Feb 14 10:14:19 CET 2013


Hi Christoph,

I believe zeromq does this is by design. It copies the data if the message size is small and reference counts it if its above a certain size.

It looks like the size threshold is specified by the max_vsm_size enum in msg.hpp, currently set to 29, so if you make your message size 30 it should
switch to reference counting.

Regards,

Richard.




From:	"Christoph Heindl" <christoph.heindl at gmail.com>
To:	zeromq-dev at lists.zeromq.org
Date:	14/02/2013 07:38 AM
Subject:	[zeromq-dev] C++ Move Constructor and Assignment Operator
Sent by:	zeromq-dev-bounces at lists.zeromq.org



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_______________________________________________
zeromq-dev mailing list
zeromq-dev at lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

===========================================================
The information in this email is confidential, and is intended solely for the addressee(s). 
Access to this email by anyone else is unauthorized and therefore prohibited.  If you are 
not the intended recipient you are notified that disclosing, copying, distributing or taking 
any action in reliance on the contents of this information is strictly prohibited and may be unlawful.
===========================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130214/1030a601/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130214/1030a601/attachment.gif>


More information about the zeromq-dev mailing list