Oliver Smith wrote:

> I'll put some thought into a better write-up for you, something a little 
> less "wary" of getting a TBB-forum thread deleted or something :)

That would be great.
> In short: what I wanted to achieve was:
> 
> void sendMe(void* ptr)
> {
>    message_t msg(&ptr, sizeof(ptr)) ;
>    outSocket.send(msg, 0) ;
> }
> 
> but for some reason this failed horribly. I didn't take the time to 
> investigate because, again, I wanted POC before going under the hood :) 
> I had three overdue deadlines and needed parallelism a week ago and on 
> top of this MySQL's Prepared Statement system was kicking me in the behind.
> 
> In hindsight, I suspect that I forgot to do the '&' in '&ptr' :)

Ah, I see. The point is that initialising the message this size means 
that you are handing it a buffer. No copy is done. In your case the 
"buffer" happens to reside on stack and is thus overwritten later on, 
corrupting the data.

What you need is to ask 0MQ to allocate the buffer for you (keep in mind 
that for VSMs this doesn't translate to actual malloc/new):

message_t msg (sizeof (ptr));
*(void**) msg.data () = ptr;

That's it.

Martin
_______________________________________________
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to