我必须集成来自 tetgen(网格生成器)的代码,这显然是经常使用的。但是,我必须使用旧版本(1.4.3 而不是 1.5),这给了我一个“写访问冲突”。相关功能在这里:
void tetgenmesh::dummyinit(int tetwords, int shwords)
{
unsigned long alignptr;
// Set up 'dummytet', the 'tetrahedron' that occupies "outer space".
dummytetbase = (tetrahedron *) new char[tetwords * sizeof(tetrahedron)
+ tetrahedrons->alignbytes];
// Align 'dummytet' on a 'tetrahedrons->alignbytes'-byte boundary.
alignptr = (unsigned long) dummytetbase;
dummytet = (tetrahedron *)
(alignptr + (unsigned long) tetrahedrons->alignbytes
- (alignptr % (unsigned long) tetrahedrons->alignbytes));
// Initialize the four adjoining tetrahedra to be "outer space". These
// will eventually be changed by various bonding operations, but their
// values don't really matter, as long as they can legally be
// dereferenced.
dummytet[0] = (tetrahedron) dummytet;
dummytet[1] = (tetrahedron) dummytet;
dummytet[2] = (tetrahedron) dummytet;
dummytet[3] = (tetrahedron) dummytet;
...
...
...
}
'dummytetbase' 和 'dummytet' 都是双***指针,四面体是双**指针。
示例值为:
'tetwords' 是:12。
'(无符号长)四面体->对齐字节':8。
'tetwords*sizeof( tetrahedron) + tetrahedrons->alignbytes' 是:104。
'(alignptr % (unsigned long)tetrahedrons->alignbytes)' 是:0。
代码编译得很好,但是当应该完成从“dummytet”到“dummytet [0]”的指针转换时,我得到了这个“写访问冲突”。
因此, dummytet 获得了 dummytetbase + 8 的地址。而且 dummytet[x] 获得了所有相同的地址,但这会导致写入冲突。
知道为什么会这样吗?谢谢!