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!阅读原文】。感谢您的支持!

您可能感兴趣的

Kotlin 空降“上位”已满月,有对你带来变化吗?... 自从5.18 Google IO 大会到现在,Kotlin 已实打实的“上位”一个月。不知道你自己或者身边有没有人开始学习和使用 Kotlin 呢? Kotlin 有对你带来什么变化吗? 欢迎回复讨论 。 Kotlin 的空降似乎让许多人措手不及,在此之前国内关于 Kotlin ...
使用 Java 注解自动化处理对应关系实现注释代码化... 概述 假设我们要从一个 ES 索引(相当于一张DB表)查询数据,ES表有 order_no, order_type, state 等字段, 而应用对象则有属性 orderNo, orderType, state等。这样,就会面临“将应用对象的属性与ES字段对应起来”的问题。 固然可以通过注释...
How do I notify all the waiting wires on another m... Let's say you have a bank account. You have two synchronized methods public synchronized void withdraw ( int amount, String name ) { while ( ...
Configurations: Are You Doing it Wrong? Let’s go over some configuration formats that most of us may be familiar with. Talking about the good old days (not really sure about “good” though), ...
一个两年java程序猿的2017个人总结 前言 又到了一年中最后的日子了,相信有不少公司要求员工写年度总结了,我也不例外。不过个人感觉在公司的写个年度总结来说,过于模板化了。其实很多没有必要。总之,本篇的个人总结,是按照个人的想法写的。简而言之,就是放开了说,放开的写! 今年事件先做个列表,然后再对该列表的事件进行说明。...