Aligned memory management?

后端 未结 7 1903
清歌不尽
清歌不尽 2020-12-13 05:00

I have a few related questions about managing aligned memory blocks. Cross-platform answers would be ideal. However, as I\'m pretty sure a cross-platform solution does not

7条回答
  •  余生分开走
    2020-12-13 05:22

    You might be able to jimmy (in Microsoft VC++ and maybe other compilers):

    #pragma pack(16)

    such that malloc( ) is forced to return a 16-byte-aligned pointer. Something along the lines of:

    ptr_16byte = malloc( 10 * sizeof( my_16byte_aligned_struct ));

    If it worked at all for malloc( ), I'd think it would work for realloc( ) just as well.

    Just a thought.

    -- pete

提交回复
热议问题