iterators are they as fast as pointers?

Started by
11 comments, last by Tachikoma 12 years, 11 months ago
[font=arial, verdana, tahoma, sans-serif][size=2]

I have a hunch (though it's just a hunch) that iterators are just as efficient as pointers...although I have no experience to back that up.


[/font]
Regular pointers are iterators. This is by design. For many implementations, the iterator for some classes such as std::vector are simply raw pointers.


Several iterator classes do additional work, but that is the design of the object. Going to the next object of a linked list, binary tree, or hashed container obviously requires some processing. Generally the processing is minimal.

Lots of expert programmers have reviewed the code; for a general purpose library the major implementations are extremely good. Obviously there are occasional improvements you can make by removing the general purpose nature of the library, but then it would no longer be the standard library.

Unfortunately, a certain popular compiler enables iterator debugging for you by default, which makes them slow as hell unless you turn that feature off.


Only a few items have iterator debugging in the Visual C++ implementation, and they are easily seen in the documentation. Most of them do not. And debugging features are generally best turned off in final builds, iterator debugging included.
Advertisement
I come from a C background so have been using pointers for many years...just getting to grips with C++ in the last few years....still got a way to go :)

I've just got to get "frobnicate" in the next game I do...even if it's in the special thanks section for the credits - LOL !

I wouldn't worry about the performance issues too much, aim for a more robust coding practices. One situation where iterator overheads should be investigated is when operating on very large, tightly-packed POD data sets, and buffers, etc.
Latest project: Sideways Racing on the iPad

This topic is closed to new replies.

Advertisement