What does posix_memalign/memalign do

后端 未结 7 952
醉梦人生
醉梦人生 2020-12-04 06:30

I\'m trying to understand what functions memalign() and posix_memalign() do. Reading the available documentation didn\'t help.

Can someone

7条回答
  •  有刺的猬
    2020-12-04 07:09

    Deffault malloc return pointer that are multiple of 8, It's mean malloc split memory to chunks have 8 bytes and check free memory at start of each chunk. There are 2 faces of problem.

    Larger chunk will waste more memory, but larger chunk help C find free chunk memory faster. memalign can change how big those chunk is. If you want to save memory, decrease chunk's size to 2 or 4. If you want to make your application faster, increase chunk's size to power of 2.

提交回复
热议问题