Why use _mm_malloc? (as opposed to _aligned_malloc, alligned_alloc, or posix_memalign)

前端 未结 3 2057
清歌不尽
清歌不尽 2020-12-05 09:48

There are a few options for acquiring an aligned block of memory but they\'re very similar and the issue mostly boils down to what language standard and platforms you\'re ta

3条回答
  •  庸人自扰
    2020-12-05 10:14

    _mm_malloc seems to have been created before there was a standard aligned_alloc function, and the need to use _mm_free is a quirk of the implementation.

    My guess is that unlike when using posix_memalign, it doesn't need to over-allocate in order to guarantee alignment, instead it uses a separate alignment-aware allocator. This will save memory when allocating types with alignment different to the default alignment (typically 8 or 16 bytes).

提交回复
热议问题