Libev uses three data structures to storage different watchers.
Heap: for watchers that sorted by time, such as ev_timer
and ev_periodic
.
Linked list: such as ev_io
, ev_signal
, ev_child
and etc.
Array: such as ev_prepare
, ev_check
, ev_async
and etc.
There is no doubt about that uses heap to store timer watcher. But what is the criteria of selecting linked list and array?
The data structure that stores ev_io watchers seems a little complex. It first is an array that with fd
as its index and the element in the array is a linked list of ev_io watcher
. It is more convenient to allocate space for array if use linked list as element. Is it the reason?
Or just because of the insert or remove operation of ev_io
is more frequently and the ev_prepare
seems more stable?
Or any other reasons?