Is it better to allocate memory in the power of two?

后端 未结 11 1043
执笔经年
执笔经年 2020-12-08 04:26

When we use malloc() to allocate memory, should we give the size which is in power of two? Or we just give the exact size that we need?
Like



        
11条回答
  •  盖世英雄少女心
    2020-12-08 04:51

    With today's amount of memory and its speed I don't think it's relevant anymore.

    Furthermore, if you're gonna allocate memory frequently you better consider custom memory pooling / pre-allocation.

提交回复
热议问题