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 API takes raw c-style pointers as arguments, for example int* in the case above.
My questions:
- Are there implementation guarantees in the stl that vector is, internally, consecutive in memory?
- Can I safely cast a std::vector to int* and expect that to work?
- In the case of a vector of vectors, can I still assume this holds true? I would expect the vector to hold other state data, or alignment issues, or maybe something else...
- What is the best way to approach this? Write a custom 2d data structure that holds an internal, contiguous-in-memory buffer and work with that? I'd have to copy to/from vectors a lot...
Thanks.