相关疑难解决方法(0)

分配向量时,它们是在堆还是堆栈上使用内存?

以下所有陈述都是正确的吗?

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)

如何存储在内部分配Typevector或任何其他STL容器?

c++ heap stack stl vector

140
推荐指数
4
解决办法
8万
查看次数

堆栈和堆上的STL容器

如果std :: vector和朋友自我调整大小,这是否意味着如果我声明一个这样的向量:

std::vector<string> myvec;
Run Code Online (Sandbox Code Playgroud)

然后它将使用更多堆栈调整大小,而:

std::vector<string> *myvec = new std::vector<string>();
Run Code Online (Sandbox Code Playgroud)

会使用更多堆调整大小吗?

c++ memory-management stl

18
推荐指数
2
解决办法
9351
查看次数

标签 统计

c++ ×2

stl ×2

heap ×1

memory-management ×1

stack ×1

vector ×1