Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the occupancy of a 16-slot ring buffer with these indices, under the one-empty-slot convention?

write = 3;
read  = 14;

  • A.5 items
  • B.11 items
  • C.3 items
  • D.14 items

Answer: A

The write index has wrapped past the end, so the occupancy is the write index minus the read index taken modulo sixteen: three minus fourteen is minus eleven, and adding sixteen gives five. Doing that arithmetic with a mask rather than a conditional is why the size is a power of two.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.