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

  • SEARCH
  • Home
  • 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 8268029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:44:15+00:00 2026-06-08T05:44:15+00:00

I still often use console output to get ideas what’s going on in my

  • 0

I still often use console output to get ideas what’s going on in my code.
I know this may be a bit old fashion, but I also use this to “pipe” stdout
into log files etc.

However, it turns out that the output to the console is slowed down for some
reason. I was wondering if someone can explain why an fprintf() to a console
window appears to be sort of blocking.

What I’ve done/diagnosed so far:

  1. I measured the time a simple
    fprintf(stdout,"quick fprintf\n");
    It needs: 0.82ms (in average). This is considered by far too long since a vsprintf_s(...) writes the same output into a string in just a few microseconds. Therefore there must be some blocking specifically to the console.

  2. In oder to escape from the blocking I have used vsprintf_s(...) to copy my output into a fifo alike data structure. The data structure is protected by a critical section object. A separate thread is then unqueing the data structure by putting the queued output to the console.

  3. One further improvement I could obtain by the introduction of pipe services.
    The output of my program (supposed to end up in a console window) goes the following way:

    • A vsprintf_s(...) formats the output to simple strings.
    • The strings are queued into a fifo alike data structure, a linked list sructure for example. This data structure is protected by a critical section object.
    • A second thread dequeues the data structure by sending the output strings to a named pipe.
    • A second process reads the named pipe and puts the strings again into a fifo alike data
      structure. This is needed to keep the reading away from the blocking output to the console.
      The reading process is fast at reading the named pipe and monitors the fill level of the pipes buffer continuously.
    • A second thread in that second process finally dequeues the data structure by fprintf(stdout,...) to the console.

So I have two processes with at least two threads each, a named pipe between them, and fifo alike data structures on both sides of the pipe to avoid blocking in the event of pipe buffer full.

That is a lot of stuff to just make sure that console output is “non-blocking”. But the result is
not too bad. My main program can write complex fprintf(stdout,…) within just a few microseconds.

Maybe I should have asked earlier: Is there some other (easier!) way to have nonblocking console output?

  • 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-08T05:44:17+00:00Added an answer on June 8, 2026 at 5:44 am

    I think the timing problem has to do with the fact that console is line buffered by default. This means that every time you write a '\n' character to it, your entire output buffer is sent to the console, which is a rather costly operation. This is the price that you pay for the line to appear in the output immediately.

    You can change this default behavior by changing the buffering strategy to full buffering. The consequence is that the output will be sent to console in chunks that are equal to the size of your buffer, but individual operations will complete faster.

    Make this call before you first write to console:

    char buf[10000];
    setvbuf(stdout, buf, _IOFBF, sizeof(buf));
    

    The timing of individual writes should improve, but the output will not appear in the console immediately. This is not too useful for debugging, but the timing will improve. If you set up a thread that calls fflush(stdout) on regular time intervals, say, once every second, you should get a reasonable balance between the performance of individual writes and the delay between your program writing the output and the time when you can actually see it on the console.

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

Sidebar

Related Questions

i am still new to the Java language and libraries... i often use this
I often use this code in winforms applications to wait for events, without using
still a bit of a n00b on SharpSVN, I'm looking to get some simple
Still learning Objective-C / iPhone SDK here. I think I know why this wasn't
I have some e-commerce code that I use often that uses Linq To SQL
This is a general design question. We often use interfaces to decouple components, write
Still working through JQuery to get data and repopulate portions of a page. Right
Still having issues with this problem. Please help if you can. So I am
Still fighting with templates. In this example, despite the fact that is copied straight
I often use and re-use usercontrols in my apps. For example, if a user

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.