Thread: Speeding up WriteConsoleOutput() on Windows 7

  1. #1
    Registered User inequity's Avatar
    Join Date
    Nov 2010
    Seattle, Washington

    Speeding up WriteConsoleOutput() on Windows 7

    So I've got to write a game that uses the windows console. This makes very little sense, but I haven't got a choice in the matter.

    We're displaying our graphics in the console using WriteConsoleOutput().

    We're loading in bitmap sequences for our animations, and parsing bitmaps into our tilemaps. It's all loading in fine and displaying perfectly. Input is working well and everything is drawing correctly.

    Our problem WriteConsoleOutput(), which is a very, very slow function, even though we're only trying to write 2000 CHAR_INFO's @ 30 times a second.

    However, on windows XP, the problem doesn't exist. It runs at least 3x faster and the tearing isn't even noticeable.

    I guess I'm just wondering what changed in the console between XP and 7 aside from limiting non WIN32 applications to 32mb of ram.

    If anybody knows any workaround for this, or possible alternatives to WriteConsoleOutput(), it would be greatly appreciated. I know there's a way, it's just probably not obvious or practical in any sense.

    But like I said, I've got to do it in the console, so any help aside from "DONT TRY TO DO GRAPHICS IN THE CONSOLE" would be accepted with open arms.

    I've considered trying to re-write WriteConsoleOutput but I'm not sure if this is even possible.


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Use the ncurses approach, keep a local "image" of what is on screen and then only write things that have changed.

    If there is any static data on screen, this will really cut down on the "2000 CHAR_INFO's @ 30 times a second".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User inequity's Avatar
    Join Date
    Nov 2010
    Seattle, Washington
    Sadly, this project requires that I only use a combination of windows.h, C standard libraries, or conio.h.

    It's for a 6-month long project (that I'm 3 moths into) for my school.

    I know this question probably won't get a very solid answer, but I was just wondering if anybody had any possible insight into this specific function.

    But since WriteConsoleOutput can only write the entire buffer (and it's CHAR_INFO's, so that's the ascii char and the Attributes), I could use WriteConsoleAttributes to do it slightly differently, because I'm only using 16 colors therefore always using spaces and no dither characters. Seeing as I'm only uses spaces, I could just write the Attributes of what had changed (which writes specifically starting at a certain COORD as opposed to WriteConsoleOutput writing the entire buffer), and maybe save some time.

    But from what I've tested the aforementioned method is slower than WriteConsoleOutput().

    Anyhow, thanks, I figured this wouldn't be a very solveable problem, but I appreciate the input.

  4. #4
    Join Date
    Aug 2010
    Ontario Canada
    FWIW... Console output is only one of many things Windows 7 does poorly... Try high bitrate audio through a USB connected DAC sometime...

    I don't do much console stuff but in what little I have the slowness was obvious. Sorry to say, I don't have a solution for you.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    >> Use the ncurses approach ...

    >> But since WriteConsoleOutput can only write the entire buffer ...
    It writes to the rectangular region that you provide.
    Things I would try:
    1) Call WriteConsoleOutputW
    2) Only call WriteConsoleOutputW for the smallest region that has changed
    3) Limit the number of times you call WriteConsoleOutputW per second by accumulating changes into a back buffer.
    4) On the EXE, set compatibility settings to XP


  6. #6
    Registered User inequity's Avatar
    Join Date
    Nov 2010
    Seattle, Washington
    Okay. So I multithreaded the program and that removed the lag that I was seeing from WriteConsoleOutput() because that is the sole job of the new thread, so the game is updating independently of the slow function.

    My issue now is just that of the tearing, which I'm not sure how to solve entirely because I can't detect the when the last WriteConsoleOutput has finished (so I can't really figure out the "VBLANK" if you will). The function is actually running really fast now, causing a slight bit of flickering when nothing is moving. I haven't really implemented any good framerate controller though, just using clock() and I think I've heard that's pretty inconsistent.

    Codeplug, I think your advice is pretty sound. I've considered using WriteConsoleOutputAttribute because I'm only editing the Attributes and not the Chars, but it seemed pretty slow when I tried writing the whole buffer with it.

    But if I can manage to monitor the changes I can probably do something more effective than I'm doing now. Ideally I could figure out how tell when WriteConsoleOutput has finished writing, but I doubt that will end up happening.

    Thanks dudes

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  2. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  3. Tetris Questions
    By KneeGrow in forum Game Programming
    Replies: 19
    Last Post: 10-28-2003, 11:12 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM