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

后端 未结 11 1046
执笔经年
执笔经年 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:44

    It might have been true once, but it's certainly not better.

    Just allocate the memory you need, when you need it and free it up as soon as you've finished.

    There are far too many programs that are profligate with resources - don't make yours one of them.

提交回复
热议问题