由C11aligned_alloc分配的内存的重新分配是否保持对齐? [英] Does realloc of memory allocated by C11 aligned_alloc keep the alignment?
本文介绍了由C11aligned_alloc分配的内存的重新分配是否保持对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下(C11)代码:
Consider the following (C11) code:
void *ptr = aligned_alloc(4096, 4096);
... // do something with 'ptr'
ptr = realloc(ptr, 6000);
由于ptr
指向的内存具有与aligned_alloc
相同的4096字节对齐方式,在(成功)调用realloc
之后,它会(保持:读取)是否会保持该对齐方式?还是可以将内存还原为默认对齐方式?
Since the memory that ptr
points to has a 4096-byte alignment from aligned_alloc
, will it (read: is it guaranteed to) keep that alignment after a (successful) call to realloc
? Or could the memory revert to the default alignment?
推荐答案
对齐方式不与指针保持一致.调用realloc时,只能依靠realloc保证的对齐方式.您需要使用aligned_alloc来执行任何重新分配.
The alignment is not kept with the pointer. When you call realloc you can only rely on the alignment that realloc guarantees. You'll need to use aligned_alloc to perform any reallocations.
这篇关于由C11aligned_alloc分配的内存的重新分配是否保持对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文