Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

will stl deque reallocate my elements (c++)?

Tags:

c++

deque

Hi I need an stl container which can be indexed like a vector but does not move old elements in the memory like a vector would do with resize or reserve (Unless I call reserve once at the beginning with a capacity enough for all elements, which is not good for me). (Note I do address binding to the elements so I expect the address of these elements to never change). So I've found this deque. Do you think it is good for this purpose? Important: I need only pushback but I need to grow the container on demand in small chunks.

like image 330
user1132655 Avatar asked Nov 05 '12 15:11

user1132655


1 Answers

std::deque "never invalidates pointers or references to the rest of the elements" when adding or removing elements at its back or front, so yes, when you only push_back the elements stay in place.

like image 115
Fred Foo Avatar answered Oct 04 '22 05:10

Fred Foo