タグ

memoryとalignmentに関するtyruのブックマーク (1)

  • malloc(3) でハマッタのでメモッタ。 - GONE WITH THE MEDICINE

    どもです。 オートミールをべ始めたせいか,便通がよろしいようで,快便ですたいっ! malloc(3) ではまる。 メモリ関連のコードを書いていて,テストを書いて,テストでこけた。 printf で原因を調べると,どうやらアラインメントの問題でこけているようだった。 あるサイズの倍数のアドレスで割り当ててるはずが,そうなってない。 自分で書いたコードには問題が見つからず。 というわけで,man malloc してみた。 一部抜粋。 For calloc() and malloc(), return a pointer to the allocated memory, which is suitably aligned for any kind of variable.どうやら,calloc(), malloc() ともに, いい具合にアラインメントを調整してくれるようだ。 何がいい具合か知

    malloc(3) でハマッタのでメモッタ。 - GONE WITH THE MEDICINE
    tyru
    tyru 2011/04/14
    > If you need a block whose address is a multiple of a higher power of two than that, use memalign, posix_memalign, or valloc.
  • 1