Output to Terminal

Hi,

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

Is there a solution for this?
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?
closed account (S6k9GNh0)
I don't think he's wanting to clean the buffer.
Last edited on
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!
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.
Output to a file.
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
On Unix typically the bottleneck is X, not the terminal itself. In that case, you could
try redirecting output to file.
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.