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
Are there implementation guarantees in the stl that vector is, internally, consecutive in memory?
Although I cannot quote the standards here, I have seen code in high-quality libraries assuming this layout (namely, POCO).
Can I safely cast a std::vector to int* and expect that to work?
Specifically, you cannot recast the vector itself. But, I have seen the following code:
std::vector vec;
int* ptr = &vec[0];
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...
You probably cannot cast a vector of vectors to a linear array. Each vector will reserve its own memory range and you cannot expect all of these ranges to be sequencial.