c++ - Does a vector<std::array<float,10>> of size 5 result in 50 contiguous floats? -
this question has answer here:
- are std::vector elements guaranteed contiguous? 7 answers
- correct way work vector of arrays 4 answers
the suggested duplicates not directly answer particular question. 1 of them addresses contiguity of elements of vector without talking array while other discusses use of array instead of float[n] without talking contiguitiness (is word?).
does vector<std::array<float,10>> of size()=5 result in 50 contiguous floats in memory, such pointer vector[0] element points start of stretch of memory?
yes. @ least if create one.
arrays not copyable in c++ have hard time trying insert them in array.
update: yes, vector<array<float, n>> has contiguous memory because vector has requirement , array layout compatible native arrays, no padding or may in middle.
note vector<vector<float>> not have contiguous memory, because each vector has additional fields.
Comments
Post a Comment