我知道编译器可以将多个非易失性加载合并为单个加载。这是否意味着内存映射函数可以创建未定义的行为?
例如:
int k = *p;
unmapFile(fm, fileHandle1);//the unmapped memory includes the address pointed to by p
//p is no longer valid, pointing to a virtual address that is unmapped
mapFile(fm, fileHanlde2);//p now points to an address somewhere in a different file
int j = *p;
//use k and j here
p 的两个取消引用是否可以合并为一个,从而导致代码行为不可预测?
另外,我知道文件映射函数不允许您指定映射的起始地址(至少在 posix 和 windows 中),但这是我能想到的最简单的假设。这种范例确实有用例。