我的部分代码很难:
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;
}
Run Code Online (Sandbox Code Playgroud)
大部分时间都在程序中.HistoryQueue中的元素数量为200k +.这可能是因为.NET中的队列在内部实现为链表吗?
什么是更好的方式来解决这个问题?基本上,类应该像FIFO一样开始丢弃~500k样本的元素,我可以选择DisplayedLength元素并将它们放入OutputField.我正在考虑编写自己的Queue,它将使用循环缓冲区.
该代码适用于较低的值.DisplayedLength是500.
谢谢,
大卫