【发布时间】:2012-04-19 22:59:03
【问题描述】:
如果我们假设我将一块内存与 memalign 对齐到 4bytes ,这样做是否仍然安全:
unsigned int* source = In.Data;
unsigned int* dest = Out.Data;
int loops = In.Size / 4; //size is the same for both in/out
while (loops)
{
*dest++=*source++;
loops--;
}
而不是一次复制 1 个字节?如果不是,如何判断内存是否正确对齐,以便在需要时回退到标准字节副本?
【问题讨论】:
-
你必须将内存对齐到
alignof(unsigned int),而不是“4字节”。 -
是的,我这样做 (sizeof(unsigned int)) D:
-
不过,一般不需要
alignof(T) == sizeof(T)。例如,考虑long double类型。