89. Circular Buffer-I

Question.5

A developer replaces the modulo in a circular buffer with a bitmask for performance:

#define BUF_SIZE 16  // Power of 2

cb->head = (cb->head + 1) & (BUF_SIZE - 1);
// Instead of: (cb->head + 1) % BUF_SIZE

Is this optimization valid? What is the constraint?

Need Help? Refer to the Quick Guide below

Select Answer

Restart quiz!