Re: array index and modulo
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: array index and modulo
- From: Enrico Colombini <erix@...>
- Date: 2007年3月29日 17:07:16 +0200
Ralph Hempel wrote:
-- this needs to be atomic
buffer[head] = "Some new data"
head = head + 1
-- this needs to be atomic
data = buffer[tail]
buffer[tail] = nil
tail = tail + 1
Is there a severe performance penalty for this? What happens
when the index wraps around?
There is an interesting estimate in the PiL book. I don't remember the
numbers, but the program would have to run for a *really* long time for
wrap-around to happen.
In practice, it can be used safely in almost all applications.
Enrico