以下所有陈述都是正确的吗?
vector<Type> vect; //allocates vect on stack and each of the Type (using std::allocator) also will be on the stack
vector<Type> *vect = new vector<Type>; //allocates vect on heap and each of the Type will be allocated on stack
vector<Type*> vect; //vect will be on stack and Type* will be on heap.
Run Code Online (Sandbox Code Playgroud)
如何存储在内部分配Type的vector或任何其他STL容器?
我需要表示一个2D场(轴x,y),我遇到一个问题:我应该使用一维数组还是二维数组?
我可以想象,重新计算1D数组的索引(y + x*n)可能比使用2D数组(x,y)慢,但我可以想象1D可能在CPU缓存中.
我做了一些谷歌搜索,但只找到关于静态数组的页面(并说明1D和2D基本相同).但我的阵列必须是动态的.
有啥
动态1D阵列还是动态2D阵列?
谢谢 :)
我在YouTube上看到了这个视频:https://www.youtube.com/watch?v = YQs6IC-vgmo,其中Bjarne说最好使用向量而不是链接列表.我无法掌握整个事情,所以任何人都可以用外行的话来解释他说的话吗?
PS:我是一名高中生,可以轻松处理链接列表,但我正在努力学习自己的向量.你能建议学习载体的任何来源吗?
SSO 解释说小字符串分配在堆上:好的,但是当在容器内构造时,这些内容不应该在堆栈上,因为容器可以在函数中创建并返回,而函数堆栈会过时。
所以我猜 SSO 不适用于 STL 容器,是吗?
c++ ×4
stl ×2
vector ×2
arrays ×1
c ×1
containers ×1
heap ×1
linked-list ×1
performance ×1
stack ×1