Non Blocking output..

This is a discussion on Non Blocking output.. within the C++ Programming forums, part of the General Programming Boards category; I have a client server program and the server displays a lot of debugging data.. but the use of cout ...

  1. #1
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683

    Non Blocking output..

    I have a client server program and the server displays a lot of debugging data.. but the use of cout seems to slow down the running since my guess is cout is a blocking call.. is there a non blocking call which will write to the screen...

    thanx for any help

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    just add flush to your cout calls or change the buffer size of cout

  3. #3
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    how do i change the buffer size..
    tahnx in advance again..

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I'm sure there is a better/easier way but the following will give you a buffer of 0 so it will output everything immediatly.
    The MyStreamBuf class was taken and trimed from
    http://cboard.cprogramming.com/showt...398#post377398
    Code:
    #include <iostream>
    #include <cstdio>
    
    class MyStreamBuf : public std::streambuf {
      public:
        MyStreamBuf(FILE *outFile)
          : o(outFile)
          {
            setg(buf, buf+1, buf+1);
          }
      protected:
        virtual int overflow (int c = EOF)
        {
          return fputc(c, o);
        }
      private:
        FILE *o;
        char buf[1];
    };
    
    int main()
    {
      MyStreamBuf buff(stdout);
      cout.rdbuf(&buff);
      cout<<"Hello World\n";
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 06:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21