Hacker News new | ask | show | jobs
by rkevingibson 3473 days ago
I'm curious what you think the problems are that unbounded indices causes? Unsigned overflow is well defined in C++, so I don't see the problem here. AFAIK, the only issue would be with requiring power of 2 sizes.
1 comments

Yeah. Just requires power of 2 sizes and handling of write_idx < read_idx.
AFAIK write_idx < read_idx case is handled automatically by doing the unsigned subtraction.

Power of 2 requirement stands, though.

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 231 everything works fine as long as computation is done with unsigned integers.
(too late to edit)

HN ate my asterisks. s/231/2^31/