少效用能缓冲多少?

hae*_*lix 2 linux less

我很好奇。

您可以less毫无问题地读取 100 GB 的文件。但是,如果您cat将 100 GB 的文件放入 . less,我认为less必须缓冲整个文件,因为文件和更少之间有一个管道(是 64K 吗?)。

那么,任何人都知道 中的缓冲策略less,它会从头开始缓冲直到内存耗尽吗?

ypn*_*nos 6

的联机帮助页less涵盖了该主题:

   -bn or --buffers=n
          Specifies  the  amount of buffer space less will use for each file,
          in units of kilobytes (1024 bytes).  By default 64K of buffer space
          is  used  for  each  file  (unless  the  file is a pipe; see the -B
          option).  The -b option specifies instead that n kilobytes of  buf?
          fer  space  should be used for each file.  If n is -1, buffer space
          is unlimited; that is, the entire file can be read into memory.

   -B or --auto-buffers
          By default, when data is read from a pipe,  buffers  are  allocated
          automatically  as  needed.   If a large amount of data is read from
          the pipe, this can cause a large amount of memory to be  allocated.
          The  -B  option  disables  this automatic allocation of buffers for
          pipes, so that only 64K (or the amount of space specified by the -b
          option)  is  used  for  the pipe.  Warning: use of -B can result in
          erroneous display, since only the most recently viewed part of  the
          piped data is kept in memory; any earlier data is lost.
Run Code Online (Sandbox Code Playgroud)

联机帮助页暗示缓冲区最终将与整个输入一样大,如果您不通过 -B 和 -b 选项对其进行限制。