I'd keep the dead descriptors in the array, and purge once in a while.
I'd also maintain the location of each descriptor, for easy removal, but this can be optimized further.
The trick is to keep invalid descriptors in the array instead of rearranging the array every time.
For instance:
struct pollfd pfds[MY_MAX_FDS];
int nfds = 0;
enum { INVALID_FD = -1 };
....
typedef std::map<int,int> desc_to_index_t;
desc_to_index_t d2i;
....
// add descriptor
if (nfds == MY_MAX_FDS){
// purge old fds
// go through pfds and remove everything that has invalid fd
// pfds should point to a condensed array of valid objects and nfds should be updated as well, as long as d2i.
}
pfds[nfds] = { desc, events, revents};
d2i.insert(std::make_pair(desc,nfds));
++nfds;
....
// remove descriptor
desc_to_index_t::iterator it = d2i.find(desc);
assert(it != d2i.end());
pfds[it->second] = { INVALID_FD, 0, 0 };
d2i.erase(it);
This way you only need to purge once a certain threshold is crossed, and you don't need to build the array every time.