【发布时间】:2011-01-10 09:24:18
【问题描述】:
我的部分代码很难处理:
private void UpdateOutputBuffer()
{
T[] OutputField = new T[DisplayedLength];
int temp = 0;
int Count = HistoryQueue.Count;
int Sample = 0;
//Then fill the useful part with samples from the queue
for (temp = DisplayStart; temp != DisplayStart + DisplayedLength && temp < Count; temp++)
{
OutputField[Sample++] = HistoryQueue.ElementAt(Count - temp - 1);
}
DisplayedHistory = OutputField;
}
大部分时间都在程序中。 HistoryQueue 中的元素数量为 200k+。 这可能是因为.NET 中的队列在内部是作为链表实现的吗?
有什么更好的方法来解决这个问题? 基本上,该类应该像一个 FIFO 一样开始丢弃大约 500k 个样本的元素,我可以选择 DisplayedLength 元素并将它们放入 OutputField。我正在考虑编写自己的使用循环缓冲区的队列。
代码在计算较低的值时运行良好。 DisplayedLength 为 500。
谢谢你,
大卫
【问题讨论】: