Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7948437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:43:20+00:00 2026-06-04T01:43:20+00:00

While poking around zeroMQ (A very useful socket replacement for those who don’t know)

  • 0

While poking around zeroMQ (A very useful socket replacement for those who don’t know), I came across this question in the mailing list:

Using multiple contexts : Is there a downside to using multiple contexts?

Is there a downside to using multiple contexts? I have a class wrapper I’d like to keep as simple as possible. I can either modify it to allow multiple connects, sockets etc under a single context or leave it as is and have clients of the wrapper instantiate it multiple times.

Two downsides as I see it.

  1. Tying up resources to no good effect (extra memory footprint, another I/O thread, etc)
  2. Sockets created in different contexts cannot communicate with each other using the ‘inproc’ transport. The name ‘inproc’ is a bit of a misnomer; it really means “intracontext.”

cr

Looking back at mine and various other source code, I eventually realized that the context set-up code:

void *context = zmq_init (1); //creates the context 

void *responder = zmq_socket (context, ZMQ_REP); //creates the socket

zmq_bind (responder, "tcp://*:5555"); //and binds it

... //Do whatever you want with the socket ...

zmq_close (responder); //destructors
zmq_term (context);

Could effectively be replaced by:

void *context = zmq_init(1); //saving the context is optional

responder = zmq_socket(type); //creates the socket
//additional [context] can be provided if desired (multi-context?)

zmq_bind (responder, "tcp://*:5555"); //and binds it

... //Do whatever you want with the socket ...

zmqx_dest(); //destroys the global context, else provide alternative [context]

And that’s what I did with macros. It makes things easier to have 1 variable less to track (among 100 others). Though its far from “ideal” as it requires the macros to be within the same “function scope”, though this could be easily solved.

While my example is C, this is somewhat language-agnostic.


Hence the question, what is the point/benefit of creating such contexts?

When its actually a downside to allow such a feature? Cause I can easily foresee many (who just copy/paste/edit code), not take into account the extra overhead, and create “lots of contexts” when its not needed [seen this many times for other similar structure, though their existence has its own justification]

One of the reasons I am saying this, is the fact I am considering using zeroMQ, in a beginners game programming module. Quite largely in part due to its simplicity, and the fact that sockets tend to fry brain cells for the new guys.


Random, I actually justified the rationale of google’s V8 context system (similar question; different system):
What is the design rationale behind HandleScope?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:43:21+00:00Added an answer on June 4, 2026 at 1:43 am

    It’s a good question. If you don’t need to save the global context, why even ask the app to create it? libzmq could trivially set-up its state when needed the first time.

    However the problem with 0MQ’s older API isn’t that it forces you to use contexts, since these are a natural parent class for sockets. The problem is that having gone to the effort of creating and tracking contexts you get almost no value for your work. It seems all cost and no benefit.

    If you look at the more recent APIs, e.g. CZMQ and 0MQ/3.1 you’ll see that contexts are much more useful. In CZMQ, we cleanly shut-down and destroy all sockets when destroying a context. That is really useful. In 0MQ/3.1 we added some context configuration, such as number of I/O threads, etc. Also the API is more consistent (zmq_ctx_new, zmq_ctx_set/get, zmq_ctx_destroy) with a class model (and looks more like CZMQ too).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was poking around some HTML5 Javascript demos and came across something I've never
While poking around the questions, I recently discovered the assert keyword in Java. At
Poking around in the rails code, I ran across with_scope . From what I
While familiarizing myself with AJAX, I came across the following issue I do not
A while ago I was poking around with SQLite, trying to port some of
I am relatively new to Java and while trying out some code came across
Whilst poking around some code using a .NET Reflector for an app I don't
While reading http://en.wikipedia.org/wiki/C_preprocessor#Multiple_evaluation_of_side_effects , I came across this example: \#define max(a,b) \ ({ typeof
While studying an implementation of Group signature I came across code where Group certificate
While working with some sources written in C++ I found those macro: JNIEXPORT return_type

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.