The data structure of libev watchers

Posted by changchang on Stack Overflow See other posts from Stack Overflow or by changchang
Published on 2012-10-22T16:31:31Z Indexed on 2012/10/22 17:01 UTC
Read the original article Hit count: 135

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about data-structures

Related posts about libev