真的没有realloc()支持对齐的版本吗?

时间:2022-06-14 06:58:46

There exist several aligned versions of the venerable malloc(), e.g.:

malloc()有几个对齐的版本,例如:

#include <stdlib.h>
int posix_memalign(void **memptr, size_t alignment, size_t size);
void *aligned_alloc(size_t alignment, size_t size);

#include <malloc.h>
void *memalign(size_t alignment, size_t size);

(originating in POSIX, glibc and Linux libc respectively). But - I can't seem to find any mention of a version of realloc() which supports alignment. Has it really never been implemented? It seems pretty trivial to combine the functionality of non-aligned realloc() with the search for an aligned chunk of memory in the aligned malloc() variants.

(分别源自POSIX、glibc和Linux libc)。但是——我似乎找不到任何关于支持对齐的realloc()的版本。它真的从未被执行过吗?将不结盟的realloc()的功能与对齐的malloc()变体中的一大块内存的搜索结合起来似乎是很微不足道的。

Related:

相关:

Does realloc keep the memory alignment of posix_memalign?

realloc是否保持posix_memalign的内存对齐?

1 个解决方案

#1


4  

Aligned realloc is only implemented in Microsoft with the _aligned_realloc function. There is no POSIX version defined and no implementation in Linux. I never understood why though, because it does not seem so complicated to code in glibc. I think it's a matter of time before someone implement it considering the advent of wide SIMD instructions.

对齐的realloc只在Microsoft中使用_align ned_realloc函数实现。在Linux中没有定义POSIX版本,也没有实现。我一直不明白为什么,因为在glibc中编写代码并不复杂。考虑到大规模SIMD指令的出现,我认为这只是时间问题。

At the moment, just allocate a new block of aligned memory, copy the content and free the old pointer. This should not slow down your application anyway.

此时,只需要分配一个新的内存块,复制内容并释放旧指针。无论如何,这不会降低应用程序的速度。

#1


4  

Aligned realloc is only implemented in Microsoft with the _aligned_realloc function. There is no POSIX version defined and no implementation in Linux. I never understood why though, because it does not seem so complicated to code in glibc. I think it's a matter of time before someone implement it considering the advent of wide SIMD instructions.

对齐的realloc只在Microsoft中使用_align ned_realloc函数实现。在Linux中没有定义POSIX版本,也没有实现。我一直不明白为什么,因为在glibc中编写代码并不复杂。考虑到大规模SIMD指令的出现,我认为这只是时间问题。

At the moment, just allocate a new block of aligned memory, copy the content and free the old pointer. This should not slow down your application anyway.

此时,只需要分配一个新的内存块,复制内容并释放旧指针。无论如何,这不会降低应用程序的速度。