[zeromq-dev] c++ api issues
sustrik at 250bpm.com
Wed Oct 20 14:09:14 CEST 2010
On 10/20/2010 01:56 PM, Burak Arslan wrote:
>> How would you implement the copy constructor?
> is this a rhetorical question? from what i see, a regular deep-copying
> copy ctor would do the job. but i'm not familiar enough with 0mq
> internals to confidently answer it.
> if that does not do the job, just documenting the reason would "fix" my
> c++ users are expected to know about argument passing semantics. if the
> sole reason is to protect the user (which is what the inline
> documentation suggests), i think that restriction should be lifted as it
> prevents some simple (yet less efficient) use cases.
Ok. So, copying message using zmq_msg_copy uses an atmoic operation
which is *slow*. The intent is to be able to reference a message from
several threads at once.
However, STL containers assure that the items stored are accessed from
at most one thread at a time. Thus, the atomic operation is not needed.
In theory we can solve this by creating a proxy object that would handle
all the message references from the single thread. (I.e. message_t would
reference the proxy object that would hold the "thread-local" reference
count, which in turn would reference the shared buffer, that holds the
global (atomic) reference count.
The problem is that you have to allocate the proxy object. Which is even
slower than an atomic op.
I see no real way out.
However, what you can do is to write a simple wrapper that would use
zmq_msg_copy in copy constructor and provide that to be used by those
who care about storing messages in containers more than about extreme
> as for other points, should i file issues? are they already done? in
> which release are they going to be?
Feel free to submit a patch. It won't break anything so I'll just apply
it straight away.
More information about the zeromq-dev