0

As for vector<char> and vector<int>, the char elements and the int elements are both stored in the stack,but what about a vector<string>?

If I want to store a huge vector<string> with many strings, should I use new vector<string> to store my vector in the heap?

tadman
  • 208,517
  • 23
  • 234
  • 262
key zhao
  • 1
  • 1

1 Answers1

3

You're over-thinking this.

Just use vector<string>. It manages the allocations for you, and sizeof(std::vector<...>) is fixed and reasonable.

Even then, if you were using std::array which acts a lot more like a C array, size and all, std::string will use dynamic allocation if necessary.

Using new std::vector<...> is hardly ever necessary.

tadman
  • 208,517
  • 23
  • 234
  • 262