Java For Loop in a table

综合编程 2018-05-16 阅读原文

This question is probably best suited towards anyone with some insight into disk read scheduling.

I have the code:

for(int i = readqueue_tail; i<readqueue_head; i++)

I then use i to access elements in a readqueue array, which goes up to 255. However, once the queue is filled, it starts filling again from 0 (as these requests will have been serviced it doesn't matter).

The issue I'm having is searching from the tail up to the readqueue_head as when the head loops round and goes past 0 again the loop condition fails. How would I go about fixing this?

Other options is just use modulo.

int i = readqueue_tail;
while (i != readqueue_head)
{
    i = (i + 1) % 256;
}
Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!

您可能感兴趣的

SimpleDoubleProperty.set (doub... I have a small financial application that is showing a market data watch list (current bid price/current ask price) in a...
Java ArrayList: A Complete Guide for Beginners We all know that arrays are an important structure in  Java  which can be used to store static data. But, wha...
JAVA:一篇文章理清多态 很多人总是喜欢,或者说错误地将JAVA中的多态理解得很复杂,最常见的错误说法就是所谓“方法的多态”,他们会给出类似下面的例子来佐证“多态是指方法的多态”: //Enginner和Mechanic是Employee的子类,构造函数参数均...
《Effective Java》学习笔记六——方法 一般在方法执行之前先检查参数的有效性,如果参数值无效,那么很快它就会失败,并且清楚的抛出合适的异常。 如果这个方法没有检查参数的异常,那么可能在方法处理中出现令人费解的异常。更糟糕的有可能是,方法可以正常返回,但是却使得某个对象处于被破...
Diagnosing Java applications on the fly with Bytem... Production being affected by software issues is always an unwanted scenario. Diagnosing production issues, however, s...