1

For a vector of 128bit integer type (std::vector<__m128i> vec;), are those 128bit integers always put in contiguous memory?

dot dot dot
  • 231
  • 1
  • 9

1 Answers1

3

Yes, that is the the vector guarantee. All elements will occupy a contiguous memory block, managed by the vector object.

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
  • See http://en.cppreference.com/w/cpp/container/vector - "The elements are stored contiguously, which means that elements can be accessed not only through iterators, but also using offsets on regular pointers to elements." – Loring Nov 07 '16 at 17:31
  • Is the `__m128i` actually some kind of struct? I saw `__m128i {aka __vector(2) long long int}` when I debug my code. In this case, is the thing still contiguous in memory? – dot dot dot Nov 07 '16 at 17:38
  • @dotdotdot: Vector elements are contiguous in memory. Period. Whether the logical data you're trying to access is stored contiguously depends on what those elements are. So a `vector>` doesn't have contiguous `int`s because vectors store their data indirectly (but contiguously!). – Lightness Races in Orbit Nov 07 '16 at 17:39
  • I hope that `__m128i` has no padding... – dot dot dot Nov 07 '16 at 17:39
  • @dotdotdot: "[Variables of type _m128i are automatically aligned on 16-byte boundaries.](https://msdn.microsoft.com/en-us/library/26232t5c.aspx?f=255&MSPPError=-2147217396)" – Lightness Races in Orbit Nov 07 '16 at 17:40
  • @dotdotdot, even if it has padding, it's considered part of the element. So as far as the vector (and we) is concerned, it's contiguous. – StoryTeller - Unslander Monica Nov 07 '16 at 17:41