Resided memory for allocating a vector
Just curious that when we allocate a vector or map in a function, where its memory reside? From stackoverflow I got the answer:
vector<Type> vect;
will allocate the
vector
, i.e. the header info, on the stack, but the elements on the free store ("heap").vector<Type> *vect = new vector<Type>;
allocates everything on the free store.
vector<Type*> vect;
will allocate the
vector
on the stack and a bunch of pointers on the free store, but where these point is determined by how you use them (you could point element 0 to the free store and element 1 to the stack, say).
留言
張貼留言