【发布时间】:2011-12-01 07:33:44
【问题描述】:
Apple 正在谈论 avoiding creating a "struct of arrays" and preferring "array of structs" 以获得更好的内存性能。
在下面的示例中,我们创建了一个巨大的彩色矩形网格(32 x 48 矩形,每个 10 x 10 大)。这是生成“数组结构”吗?只是想知道我的周末会有多糟糕......
- (void)drawFrame {
// draw grid
for (int i = 0; i < numRectangles; i++) {
// ... calculate CGPoint values for vertices ...
GLshort vertices[ ] = {
bottomLeft.x, bottomLeft.y,
bottomRight.x, bottomRight.y,
topLeft.x, topLeft.y,
topRight.x, topRight.y
};
glVertexPointer(2, GL_SHORT, 0, vertices);
glColor4f(r, g, b, 1);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
【问题讨论】: