Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

channel_map中内存分配问题 #37

Open
KeshawnZhen opened this issue May 8, 2022 · 1 comment
Open

channel_map中内存分配问题 #37

KeshawnZhen opened this issue May 8, 2022 · 1 comment

Comments

@KeshawnZhen
Copy link

KeshawnZhen commented May 8, 2022

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);
        .......
    }
    ....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@KeshawnZhen and others