[zeromq-dev] how to receive a message into a static buffer?
Martin Sustrik
sustrik at fastmq.com
Tue May 5 11:01:39 CEST 2009
Hi John,
> There is a similar issue with the high-level language wrapper
> (available for all languages, at least on OpenVMS):
>
> The output buffer is returned as an address, as we already know. All
> very well for lower-level languages that know how to deal with
> addresses, but not so good for those that do not, e.g., COBOL,
> FORTRAN.
Yes, there's the same issue with all the language binding but it turns
out that it's pretty difficult to use zero-copy with higher-level
languages - especially with garbage collected languages.
> There are, of course, runtime library routines on the platform(s)
> which would allow one to copy the data from the output buffer address
> to some local variable. My thought was not to use these as they tend
> to be platform specific, thus making the program harder to port.
>
> The alternatives would appear to be:
>
> 1. pass the address and length of a local variable to the wrapper and
> have it copy the data to the local variable
Yes, however, if the message is larger then the variable, it'll result
in error. I belive you are speaking about COBOL here, right? IIRC the
variables in COBOL are fixed-length, so it may be actually the right way
to handle the issue.
> 2. add an additional call in the wrapper to perform the copy
>
> My preference is 1. above as it would only change the behavior of the
> receive call in the wrapper, not of anything else.
>
> PS: how long is the buffer available?
in C++ it's available until the message is destructed. In C wrapper
there's zmq_free function you have to call to free the buffer.
Martin
More information about the zeromq-dev
mailing list