How use alignof to force alignment for a heap allocation?

前端 未结 2 1688
梦毁少年i
梦毁少年i 2021-01-24 02:03

I\'d like to force a specific heap allocation to return an address that\'s 64-byte aligned, because that\'s a cache line boundary. I thought I could do it like this



        
2条回答
  •  终归单人心
    2021-01-24 02:26

    Ask for 64 more bytes than you need, then generate a cache aligned address within the allocated space. Taking care to free the whole allocated memory at the end.

提交回复
热议问题