1

As per this answer:

std::vector of std::vectors contiguity

A vector of vectors is not contiguous. EASTL claims that their vector is contgiuous (see: https://github.com/electronicarts/EASTL/blob/master/include/EASTL/vector.h it). Does this contiguity apply to a vector of vectors?

Hisham Hijjawi
  • 1,803
  • 2
  • 17
  • 27
  • The comment you are referring to is really old, and many of the differences listed there do not apply anymore (and some of them never did). In fact [std::vector also guarantees that the elements are stored contiguously](https://en.cppreference.com/w/cpp/container/vector) – Not a real meerkat Feb 20 '20 at 01:32
  • BTW, if this is a requirement for something you're doing, and if the size of the inner container can be fixed, consider a [vector of arrays](https://godbolt.org/z/EGXqMA) – Not a real meerkat Feb 20 '20 at 01:40

1 Answers1

1

What they mean is that the memory allocated by their vectors will be contiguous. Any memory allocated by the contained elements are not a part of this.

So yes, their vectors are contiguous. And no, that does not apply to all the contained elements as a group.

Sid S
  • 6,037
  • 2
  • 18
  • 24
  • So it's no more contigous than a regular std::vector of vectors? – Hisham Hijjawi Feb 20 '20 at 01:32
  • That's right. How could it be ? There is no way to control how contained objects allocate memory. – Sid S Feb 20 '20 at 01:36
  • Thanks, that makes sense. Does that mean it is better to use a multidimensional array instead of a vector of vectors to ensure contiguity? I can ask seperately. – Hisham Hijjawi Feb 20 '20 at 01:39
  • A multidimensional array would be contiguous, but there is still no way to control how the contained objects allocate memory, if they do. – Sid S Feb 20 '20 at 01:43