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?

user3586940
  • 865
  • 1
  • 10
  • 18
  • 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) – Cássio Renan 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) – Cássio Renan 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
  • 5,907
  • 2
  • 16
  • 23
  • So it's no more contigous than a regular std::vector of vectors? – user3586940 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. – user3586940 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