Discussion
What is the occupancy of a 16-slot ring buffer with these indices, under the one-empty-slot convention?
write = 3; read = 14;
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.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development