64位系统指针对齐
来源:互联网 发布:python buffering 编辑:程序博客网 时间:2024/06/14 18:29
MSDN中的一段话:
On 64-bit Windows, if a data structure is misaligned, routines that manipulate the structure, such as RtlCopyMemory and memcpy, will not fault. Instead, they will raise an exception. For example:
Copy
#pragma pack (1) /* also set by /Zp switch */
struct Buffer {
ULONG size; //4个字节
void *ptr; //8个字节
};
void SetPointer(void *p) {
struct Buffer s;
s.ptr = p; /* will cause alignment fault */ //因为struct的排布导致指针地址没有对齐
...
}
You could use the UNALIGNED macro to fix this:
Copy
void SetPointer(void *p) {
struct Buffer s;
*(UNALIGNED void *)&s.ptr = p;
}
Unfortunately, using the UNALIGNED macro is very expensive on Itanium-based processors. A better solution is to put 64-bit values and pointers at the beginning of the structure.
On 64-bit Windows, if a data structure is misaligned, routines that manipulate the structure, such as RtlCopyMemory and memcpy, will not fault. Instead, they will raise an exception. For example:
Copy
#pragma pack (1) /* also set by /Zp switch */
struct Buffer {
ULONG size; //4个字节
void *ptr; //8个字节
};
void SetPointer(void *p) {
struct Buffer s;
s.ptr = p; /* will cause alignment fault */ //因为struct的排布导致指针地址没有对齐
...
}
You could use the UNALIGNED macro to fix this:
Copy
void SetPointer(void *p) {
struct Buffer s;
*(UNALIGNED void *)&s.ptr = p;
}
Unfortunately, using the UNALIGNED macro is very expensive on Itanium-based processors. A better solution is to put 64-bit values and pointers at the beginning of the structure.
0 0
- 64位系统指针对齐
- 32位和64位系统区别及字节对齐
- 64位系统结构体对齐访问段错误
- 在64位系统以及64位编译器下字节对齐----阿里巴巴2015实习生笔试题
- C++ 32位系统内存对齐
- 32位系统指针占4个字节,那64位系统呢?
- linux 64位系统的指针为8字节
- 32位Linux与64位Linux系统中指针 小小差别
- 32位系统中四字节对齐问题
- sizeof,union在32位系统中的对齐问题
- 32位和64位分配空间内存对齐
- 系统32位指针变量为4字节系统16位指针变量2个字节
- 32位系统,64位系统概念
- 《c和指针》笔记--包含位域结构体的内存对齐(32bit,GCC)
- C语言指针方面的理解:(更新中)位对齐
- 32和64位系统占的字节(int char long double 指针等)
- JAVA之JDK在64位系统默认开启压缩指针分析
- class之位对齐
- 递归实现汉诺塔问题(python)
- 20个高级Java面试题汇总
- hdu 2896
- 英语笔记
- 让linux每天定时备份MySQL数据库并删除五天前的备份文件
- 64位系统指针对齐
- HDU 1051 Wooden Sticks(贪心)
- 【NOIP2010TG/codevs1066】 引水入城 解题报告
- HDU 2256 & HDU 4565 (矩阵快速幂 + 公式推演)
- Java心得14
- Onclick点击事件
- 解决问题
- 千万别误解黑客
- 在Linux下安装windows后解决Linux不能启动能问题