Y
Hacker News
new
|
ask
|
show
|
jobs
by
loeg
3473 days ago
Yeah. Just requires power of 2 sizes and handling of write_idx < read_idx.
1 comments
ashtuchkin
3473 days ago
AFAIK write_idx < read_idx case is handled automatically by doing the unsigned subtraction.
Power of 2 requirement stands, though.
link
gpderetta
3473 days ago
Yes, this exact trick is used for tcp sequence numbers, for example, which are allowed to overflow, and as long as the unack'd bytes are less than 2
31 everything works fine as long as computation is done with unsigned integers.
link
gpderetta
3473 days ago
(too late to edit)
HN ate my asterisks. s/231/2^31/
link
Power of 2 requirement stands, though.