.net - 为什么(非通用)Stack 类实现为循环缓冲区? (这到底是什么意思)?

标签 .net stack circular-buffer

非通用 Stack类声明“堆栈是作为循环缓冲区实现的。”
我不明白循环缓冲区在 Stack 用例中的应用。我也不明白堆栈如何实现为循环缓冲区。
Wikipedia说这个:

The useful property of a circular buffer is that it does not need to have its elements shuffled around when one is consumed. (If a non-circular buffer were used then it would be necessary to shift all elements when one is consumed.) In other words, the circular buffer is well suited as a FIFO buffer while a standard, non-circular buffer is well suited as a LIFO buffer.

Circular buffering makes a good implementation strategy for a queue that has fixed maximum size.


那么......堆栈是如何实现为循环缓冲区的,为什么?

最佳答案

我怀疑这是文档中的复制/粘贴/编辑错误;在反射器中查看,它不是作为循环缓冲区实现的;例如 push 是(在调整大小代码之后)基本上是:

this._array[this._size++] = obj;

偷看是:
return this._array[this._size - 1];

和流行是:
object value = this._array[--this._size];
this._array[this._size] = null;
return value;

请注意,它不使用任何类型的偏移/环绕 - 因此它实际上并未使用循环缓冲区。你的直觉看起来是正确的,但文档看起来是错误的。

关于.net - 为什么(非通用)Stack 类实现为循环缓冲区? (这到底是什么意思)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16955883/

相关文章:

c++ - 没有优先级反转的环形缓冲区

用 C 语言实现 FIR 滤波器的循环缓冲区

c# - .Net 在哪里存储泛型类型的静态字段的值?

c++ - 继续运行程序直到用户输入退出

c - 正确括号的最长子串

android - android dev 的 "stack tool"在哪里? (帮助调试 native C++ 代码)

javascript - 如何在 JavaScript 中以循环方式访问数组

.net - 使用 WinSCP .NET 的方法未找到异常 (EventWaitHandle..ctor)

.net - 为什么 ObjectDataSource 需要函数的可选参数?

c# - 在 C# 中实现 De Boor 样条算法