Skip to content

channel_map中内存分配问题 #37

Description

@KeshawnZhen

channel_map中元素的空间大小是与fd的值正相关的,而不是跟当前在线的连接数量正相关,这样做是不是有点浪费内存?

int event_loop_handle_pending_add(struct event_loop *eventLoop, int fd, struct channel *channel) {
    .......
    if (fd >= map->nentries) {
        if (map_make_space(map, fd, sizeof(struct channel *)) == -1)
            return (-1);
    }
    .....
}
int map_make_space(struct channel_map *map, int slot, int msize) {
    if (map->nentries <= slot) {
       ....
        while (nentries <= slot)
            nentries <<= 1;
         // 这里申请的内存空间与fd的值正相关
        tmp = (void **) realloc(map->entries, nentries * msize);
        .......
    }
    ....
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions