Does accessing a single struct member pull the entire struct into the Cache?

前端 未结 3 1665
小鲜肉
小鲜肉 2021-02-09 11:23

I\'ve been reading Ulrich Drepper\'s, \"What every programmer should know about memory\" and in section 3.3.2 Measurements of Cache Effects ( halfway down the page ) it gives me

3条回答
  •  难免孤独
    2021-02-09 12:12

    The hardware doesn't know the layout of the struct, but just loads a number of bytes around the accessed member into cache. And yes, the slowdown from larger structs is because they will then be spread across more cache lines.

提交回复
热议问题