next_in=(next_in+1) % BUFFER_SIZE;<----------"What is %. Please examples the number of next_in and the next value of next_in" if(next_in==next_out)
next_in=t; // Buffer full !!
What is modules(%) ????????????
Posted: Sat Dec 20, 2003 4:48 pm
Modulus is the remainder after a division.
30%4=2, because 30/4=7 with a remainder of 2.
Joined: 06 Sep 2003 Posts: 1790 Location: Norman, OK
Meaning of line
Posted: Sat Dec 20, 2003 5:16 pm
This code is a neat programming trick!
The line: next_in=(next_in+1) % BUFFER_SIZE;
causes the incoming char pointer to bump to the next available buffer location. If it is at the end of Buffer_Size then it will "wrap around" back to the beginning of the buffer. This setup is known as a "ring buffer".
The line: if(next_in==next_out) next_in=t; // Buffer full !!
checks to see if the next char coming in (location of the next_in pointer) will overwrite the next char waiting to be processed out of the ring buffer. If it will, it "resets" the pointer back to the last location used which was saved earlier in variable t.
Joined: 18 Dec 2003 Posts: 5 Location: Belgium
Posted: Sun Dec 21, 2003 1:40 pm
Increment next_in but if the result is greater than buffer_size start again at 0.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum