Output to Terminal

Sep 19, 2009 at 8:53pm
Hi,

I noted that if I put so much output to the terminal my program runs slowly.

Is there a solution for this?
Sep 19, 2009 at 11:25pm
Link to article : http://www.cplusplus.com/forum/articles/10515/

Windows Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <windows.h>

void ClearScreen()
  {
  HANDLE                     hStdOut;
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  DWORD                      count;
  DWORD                      cellCount;
  COORD                      homeCoords = { 0, 0 };

  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  if (hStdOut == INVALID_HANDLE_VALUE) return;

  /* Get the number of cells in the current buffer */
  if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
  cellCount = csbi.dwSize.X *csbi.dwSize.Y;

  /* Fill the entire buffer with spaces */
  if (!FillConsoleOutputCharacter(
    hStdOut,
    (TCHAR) ' ',
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Fill the entire buffer with the current colors and attributes */
  if (!FillConsoleOutputAttribute(
    hStdOut,
    csbi.wAttributes,
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Move the cursor home */
  SetConsoleCursorPosition( hStdOut, homeCoords );
  }


Unix Systems :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <unistd.h>
#include <term.h>

void ClearScreen()
  {
  if (!cur_term)
    {
    int result;
    setupterm( NULL, STDOUT_FILENO, &result );
    if (result <= 0) return;
    }

  putp( tigetstr( "clear" ) );
  }



Thank Duoas not me, and thank you for using a question mark and using english but why did you post this in the article section?
Sep 21, 2009 at 5:11pm
closed account (S6k9GNh0)
I don't think he's wanting to clean the buffer.
Last edited on Sep 21, 2009 at 5:12pm
Sep 21, 2009 at 9:59pm
There is no solution on the C/C++ side except to reduce the amount of output to the terminal in some way. The problem is with your terminal emulator. (If you are on Windows, I empathize. If you are on Linux, there are some fast terminal emulators out there. Eschew those with fancy add-ons.)

Good luck!
Sep 21, 2009 at 10:02pm
The terminal... slow? I thought it only held a certain amount of text, and then it began to clear lines from the top? At least, that's what happens for me.
Sep 21, 2009 at 10:24pm
Output to a file.
Sep 22, 2009 at 2:02am
Yes, all terminal emulators do it that way. Some do it better than others. (Some are also more interested in being pretty than fast.)

Output to file is also a very good idea. I forgot about that one. +1
Sep 22, 2009 at 2:31am
On Unix typically the bottleneck is X, not the terminal itself. In that case, you could
try redirecting output to file.
Sep 22, 2009 at 3:53am
X is designed so that very little information needs to be sent back and forth between server and client. All the fancy GUI drawing stuff is on the terminal. For home systems (Linux, etc), the server and client reside on the same host, so it isn't a real big problem.

The problem is the stupid terminal emulator, which is trying to do too much fancy stuff to render simple text.
Topic archived. No new replies allowed.