stl deque是否会重新分配我的元素(C ++)? [英] will stl deque reallocate my elements (c++)?

查看:51
本文介绍了stl deque是否会重新分配我的元素(C ++)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个stl容器,该容器可以像矢量一样被索引,但不会像矢量那样通过调整大小或保留值来移动内存中的旧元素(除非我一开始就调用一次reserve,并且其容量足以容纳所有元素,这对我不利).(请注意,我确实绑定了元素,因此我希望这些元素的地址永远不会改变).所以我找到了这个双端队列.您认为这对您有好处吗?重要提示:我只需要推回即可,但是我需要按需将容器分成小块.

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.

推荐答案

std:: deque 在后面或前面添加或删除元素时,永远不会使指向其余元素的指针或引用无效",因此,是的,当您仅 push_back 元素留在原处.

这篇关于stl deque是否会重新分配我的元素(C ++)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆