[zeromq-dev] STL use in zeromq

Martin Sustrik sustrik at 250bpm.com
Fri Oct 29 13:41:26 CEST 2010


Hi Mikeel,

> I was looking through the source code and I wondered if there is a
> specific reason for something I observed. 0mq uses std::vector in
> several places often typedef'ed or in through yarray.hpp. And that is
> just fine, but often when values are removed they're removed one at a
> time during an iteration across the vector (which as far as I know
> and feel free to correct me) is the slowest way to remove values from
> a std::vector. I've been taught to use the Erase-Remove idiom, but
> maybe the call overhead is higher than I think or there is another
> reason. For example the following code from ctx.cpp:
>
> void zmq::ctx_t::unregister_endpoints (socket_base_t *socket_) {
> endpoints_sync.lock ();
>
> endpoints_t::iterator it = endpoints.begin (); while (it !=
> endpoints.end ()) { if (it->second == socket_) {
> endpoints_t::iterator to_erase = it; it++; endpoints.erase
> (to_erase); continue; } it++; }
>
> endpoints_sync.unlock (); }

It's a map (RB-tree). Not a vector.

Martin



More information about the zeromq-dev mailing list