PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Iterators

I know that for long cycles it is better to save temp result:
----------------------------------
Object* object;
for (Iterator iter = something.begin(); iter != something.end(), ++iter)
{
object = *iter;
for (another cycle...) object->method();
}
-----------------------------------

Would that be any faster that way:...
-----------------------------------
Object* object;
for (Iterator iter = something.begin(); iter != something.end(), ++iter)
{
object = *(*iter);
for (another cycle...) object.method();
}

...somethig contains pointers, of couse.
joshbu [MSFT] · 05 Jul 2006, 19:50 UTC
Functional concern:

Does the class Object define operator=?

If not, you're getting a compiler generated operator, which is a simple member copy. This can be bad: for example, if one of the members is a HANDLE to a Win32 object that is destroyed in the Object destructor.

Performance concern:

Do you have profiling data that suggests that the call into Object::method is a hot spot?

In most cases, Smartphone/PocketPC apps are not CPU bound: they are memory bandwidth bound. So things like cache coherentcy can matter much, much more than trying to save cycles on method calls.