The GCC compiler is pretty smart and it should convert the % to & automatically during its optimization phase. Try it: I bet the code generated will be the same size with both approaches (as long as the modulus is a power of 2).

The GCC compiler is pretty smart and it should convert the % to & automatically during its optimization phase. Try it: I bet the code generated will be the same size with both approaches (as long as the modulus is a power of 2).

Only worth this kind of optimization in cases where serial performance was the bottleneck.

I try to do simple audio recorder from the arduino uno (just for fun and training).I programmed Timer2 for generate interrupts at 16KHz (every 62.5uS) and set ADC prescaler to 64(so, ADC conversion must take 52uS). But sometymes, ADC don't have to complete previous conversion, when the next interrupt occurs.

I think, it is because other interrupts brings a time jitter to time, when Timer2 interrupt handler raise...

And "while you are in there", why not modify the code to use 8 bit variablesfor head and tail? It saves hundreds of bytes of code to do this.It is one of the first things I change on every single Arduino release.And if you are worried about somebody making SERIAL_BUFFER_SIZE larger than 256 thenthat can also be handled compile time with a #if to change back to using ints.

But in the bigger picture, larger than 8 bit indexes won't really work anyway because the code that usesit does not properly deal with atomicity of the 2 byte value when doing things like compares.So it might as well be an 8 bit value anyway since 16 bit (multi byte) values will have issues whenthe value is larger than 255.