std::vector and c-style arrays

前端 未结 3 2005
没有蜡笔的小新
没有蜡笔的小新 2021-02-15 09:49

I am experimenting with OpenCL to increase the speed of our software. We work with maps a lot and, to simplify, represent a map as a std::vector< std::vector >. The OpenCL AP

3条回答
  •  一整个雨季
    2021-02-15 10:26

    • Are there implementation guarantees in the stl that vector is,
      internally, consecutive in memory

    Yes, it is a dynamic array. Standard guarantees that the objects inside vector are stored consecutively.

    • Can I safely cast a std::vector to int* and expect that to work?

    No, but you can use begin() and use that as the pointer.

    • Are there implementation guarantees in the stl that vector is,
      internally, consecutive in memory

    No, since vector may contain some internal member variables the whole 2D array will not be continuos memory location

提交回复
热议问题