[nanomsg] Re: Fixing compiler warnings regarding type conversions

  • From: Martin Sustrik <sustrik@xxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Tue, 01 Oct 2013 14:25:30 +0200

Hi Immanuel,

Fix follows below (MIT license). As I'm trying to understand the design
descisions, what speaks against the use of size_t in that chain of
functions, when the only variable (except of the const 1) used as a
parameter is of size_t? Or the other way around: why is the count in
nn_dist of size_t when it is used as a uint32_t? Sorry, I'm just being
curious :)

There are two different values involved here.

The first one is the reference count of the message. It's encoded as uint32_t as it is altered using CPU atomic operations and fixed-size type makes that simpler.

Then there's number of connections connected to the socket (as it appers in nn_dist class). Given that it's a number of in-memory objects, size_t seems appropriate.

Finally, the two values meet when a message is sent to *all* peers using a PUB or SURVEYOR socket. The algorithm takes the number of connections (size_t) and, instead of copying the message for every connection, it just increases the reference count of the message (uint32_t) by an appropriate amount.

HTH,
Martin

Other related posts: