Is method B any faster than method A below? I have legacy code written with method A and I need to know if there would be a performance increase if I modified it to use method B or is it just semantics?

Method A (Using pointer)

for(vector<TriggerAlgorithm*>::iterator it = _pTrigs.begin(); it != _pTrigs.end(); ++it)
{
    TriggerAlgorithm* pTrig = *it;   // Pointer to the Trigger
    pTrig->doSomething();            // Use pointer to do something
}

Method B (Using reference)

for(vector<TriggerAlgorithm*>::iterator it = _pTrigs.begin(); it != _pTrigs.end(); ++it)
{
    TriggerAlgorithm& trig = *it;   // Reference to the Trigger
    trig.doSomething();             // Use reference to do something
}

Thanks!

There is no difference as far as efficiency, references are actually implemented as pointers. The difference is in safety because references can not be changed once set.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.