i am building a network intrusion detection system using visual c++ and one of its component is a tcp session manager for the whole network. The tcp session data is stored in a concurrent vector so that it can be accessed from other threads. I found out there is no easy way to remove a session from the concurrent vector once the session is closed. So my QUESTION is what is the smartest method you know of for removing items from concurrent vectors.
Smart == fairly easy to program without too much performance hit
Thankyou
I’d consider using a
std::setinstead of a vector here – especially if the number of items stored is large. I imagine you’ll also want to perform lookups frequently.Search and removal from the set is
O(log(n))complexity rather thanO(n)for thestd::vector– although the trivial insertion case in the isO(1)rather thanO(log(n))with the set.You will also need mutex to protect all of these operations.