我有这样的结构
struct mystruct {
/* used variables */
/* cache line 1 */
<variables>
/* cache line 2 */
<variables>
...
/* unused variables */
/* cache line n */
<variables>
/* cache line n+1 */
<variables>
};
如上所示,我将类似的变量分组到结构中的缓存行中。还有一些未使用的变量(也在缓存行中分组),稍后将使用。
现在我正在使用这样的结构
struct mystruct *foo = malloc(sizeoof(struct mystruct));
while (1)
{
/* access variables from used part only */
}
据我所知,由于我没有访问结构中未使用部分的变量,因此永远不会缓存这些变量。因此,即使我在结构中存储了一些未使用的变量,代码性能也不会因为我只存储使用过的变量而降低。
我是对的吗?