定义
c
std::vector<float> vertices= {
0.0f, 0.5f, 0.0f, // x,y,z of first point.
0.5f, -0.5f, 0.0f, // x,y,z of second point.
-0.5f, -0.5f, 0.0f, // x,y,z of third point.
}
求:vertices所存储的数据的字节数?
我之前以为,答案是sizeof(vertices) = sizeof(float9) = 9 * sizeof(float) = 36
至少,起码,sizeof(vertices.data()) = 36吧?
然后我才反应过来:
-
sizeof(vertices) = 32,是
std::vector<float>对象本身所占的字节数 -
sizeof (vertices .data()) = 8,是指针大小。64 位系统为 8 字节,32 位系统为 4 字节。
所以,要求数据字节数,应该是vertices.size() * sizeof(float)。