I'm developing a server in C with the epoll library and I have a question as to how memory is handled for struct epoll_event
. I've noticed in some online examples that, when making epoll_ctl
calls, the events
argument is allocated on the stack and then the pointer is passed, like so:
struct epoll_event ev;
ev.events = EPOLLIN;
epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &ev);
Now we all know what happens to ev
when the function returns. My question is: does the epoll library make copies of these values internally or does it rely on the struct you passed to be heap allocated? Will the above example totally break my reactor implementation? If so, what is the best way of keeping track of my heap allocated epoll_event
structs?
Thanks for your time.