lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> -- 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 a memory penalty. When the start index moves away from 1, Lua
will stop storing these entries as array entries and start storing them
as hash entries. That roughly doubles the memory used by the table. Of
course, if the list is not too big, that should not be a problem. (Until
Lua 4.0 all arrays were stored as hashes, and we were all happy then.)

(As already noticed, if Lua is using doubles the index will not
wrap around before 2100.)

-- Roberto