真的没有支持对齐的realloc()版本吗? [英] Is there really no version of realloc() supporting alignment?

查看:114
本文介绍了真的没有支持对齐的realloc()版本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊贵的malloc()存在几种对齐的版本,例如:

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

#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);

(分别起源于POSIX,glibc和Linux libc).但是-我似乎找不到任何提及支持对齐的realloc()版本.真的从未实施过吗?将未对齐的realloc()的功能与在对齐的malloc()变体中搜索对齐的内存块结合起来似乎很琐碎.

(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_memalign的内存对齐? a>

Does realloc keep the memory alignment of posix_memalign?

推荐答案

对齐的重新分配仅在Microsoft中使用 glibc . 考虑到广泛的SIMD指令的出现,我认为这是一个时间问题,直到有人实施它.

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.

此刻,只需分配一个新的对齐内存块,复制内容并释放旧指针.无论如何这都不会减慢您的应用程序的速度.

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.

这篇关于真的没有支持对齐的realloc()版本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆