Subject: Re: [boost] Stack-based vector container
From: Christopher Jefferson (chris_at_[hidden])
Date: 2011-01-26 08:15:21
On 25 Jan 2011, at 23:19, Domagoj Saric wrote:
> "Christopher Jefferson" <chris_at_[hidden]> wrote in message news:C656C64C-8E00-4D67-ACE1-6A95B9A65281_at_bubblescope.net...
>> I find most modern compilers do not have issues with calling end() repeatedly, or push_back().
> push_back() is a possibly-new-calling/possibly-throwing 'fat function', in which way do you mean that modern compilers 'do not have issues' with it? And could you please name such a compiler...
for vector<int>::push_back, gcc will inline the common case (there is no need to allocate new memory) and no inline the memory allocation when the vector grows. Therefore you just end up paying for one comparison of two pointers for each push_back call, to check there is still space.
>> Also it is unclear if operator or iterators are more efficient.
> You know of a (real) use case where indexed based access is faster than pointer based?
I have found in the past, depending on the compiler and it's settings, it can be unpredictable. I don't have exact numbers, but there were points in the past where gcc's loop unroller unrolled some index based code, but not pointer based code. They may well have fixed it now.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk