Skip to content

kevent() requires a Vec for its event list, when instead it should probably take a slice #1043

Closed
@yorickpeterse

Description

@yorickpeterse

The wrapper for kevent() is defined as follows:

pub unsafe fn kevent(
    kqueue: impl AsFd,
    changelist: &[Event],
    eventlist: &mut Vec<Event>,
    timeout: Option<Duration>,
) -> io::Result<usize>

Here the eventlist argument is defined as &mut Vec<Event>, requiring a heap allocating of a Vec on every call. For a system where file descriptors are frequently (un)registered (e.g. a busy socket server), it's not unlikely for the Vec allocations to become a bit of a problem.

Would it be possible to change the signature such that eventlist is a &mut [Event] instead? This way one can simply stack allocate the slice, and still use a Vec if deemed necessary (e.g. one is expecting many events).

Some of this was discussed in #578, but it seems nothing was done in response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions