
14 May
2008
14 May
'08
2:14 p.m.
Igor R. <igor_rubinov@hotmail.com> writes:
The problem with this code is that you are returning a reference > to data that might be immediately invalidated. A push_back via > another thread can cause the referenced memory to no longer be valid. Does push_back() really invalidate iterators to *previous* vector elements?!
Yes: it might have to allocate a new chunk of memory for the vector, in which case it will have to move all the existing elements to the new memory, and free the old one. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL