3

In Windows 7, the Command Prompt has two configuration options called Buffer Size and Number of Buffers found in the Options tab. Following these instructions, I've tweaked these two values to increase the amount of history I can see by scrolling. But I'm not sure how exactly are these effecting the command prompt's history. It seems that only the screen buffer size, from the layout tab, has an affect on how much I can scroll. Can anyone explain ? Thanks in advance.

1 Answer 1

0

UPDATED: I found the answer while pondering over Eryk Sun's comment (my emphasis):

The console's line editor stores input history in a circular buffer, one per attached process (e.g. if you run diskpart.exe from cmd.exe, then two processes are attached to the console). There's a fixed number of buffers for a console window, which is set in the properties or defaults. They get destroyed with the console.

No need to run diskpart to make a demonstration! With the Number of buffers set to 4 (the default), launch a new Command Prompt, type echo 1, and check command history via F7. All fine. Now launch another cmd.exe by typing cmd inside your command window, then echo 2 and F7 again. Repeat a third time, and then a fourth time, and then a fifth time, exceeding the number of configured buffers. And here you will notice that you've run out of command buffers, and there'll be no history on pressing F7 for command interpreter number five.

And that is the meaning of Number of buffers.

I'll leave my initial answer below. Note that the Microsoft text is misleading. Tim Hofstetter's remark also seems misleading because buffers dont get "recycled"; rather, once you've run out of buffers, new contenders won't be assigned any because there's no more of them. My remarks and speculation below are irrelevant apart from the Windows version and Eryk Sun links.


In the Command-Line Reference from August 2016, Microsoft says:

To configure the Command Prompt window […]

  1. In Command History, type or select 999 in Buffer Size, and then type or select 5 in Number of Buffers. By increasing the screen buffer size to 999, you enable scrolling through the Command Prompt window. By increasing the number of buffers to five, you increase the number of lines in the Command Prompt window to 5000.

This explanation is lacking in clarity. What exactly does the Number of buffers setting achieve? First thing I've found is an answer on Quora by Tim Hofstetter:

The "Number of Buffers" setting controls how many discrete processes can have their own individualized command buffers before the buffers get recycled for additional processes.

However, I've not been able to verify this by opening five command prompts with Number of buffers set to four. Each prompt did guard its own history, and nothing got merged (but I only typed a couple commands and cannot exclude that over time with the buffers filling up they eventually might get merged). Tested on Windows 10 22H2:

► ver
Microsoft Windows [Version 10.0.19045.4651]
► where /t cmd conhost
289792   15.05.2024      07:59:47  C:\Windows\System32\cmd.exe
867840   15.05.2024      07:59:57  C:\Windows\System32\conhost.exe

I've found another page making that claim (allzpark » shells):

It just so happens that 4 is the default number of buffers the windows ConHost.exe is configured to keep track of, which means that when you launch a 5th layer you lose history.

So I can only conclude by speculating that this concept goes back to the DOS days when computers didn't have much memory so even the puny little command history could be tuned in terms of size and number of buffers. In how far it is still relevant on Windows 10 is not clear to me.

User Eryk Sun is very knowledgeable about how cmd and ConHost work together, see his comments on this other question or his answers on cmd questions. Maybe he addresses this issue somewhere.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .