我正在尝试将 C 应用程序移植到 Python,并且有很多指针。这些是否相等:
obj->position = (float*) malloc(obj->totalItems * obj->xyz * sizeof (float));
for (i = 0; i < components; i++) {
obj->comps[i].position = obj->position + obj->pOffset; // Pointer arithmetic
obj->pOffset += obj->comps[i].items * obj->xyz;
}
和
for i in range(self.totalItems * self.xyz):
self.position.append(0.0)
for i in range(self.components):
self.comps[i].position = self.position[self.pOffset:] # Position was a C pointer
self.pOffset += self.comps[i].items * self.xyz
我知道 Python 对象是通过引用传递的,所以我想知道是否:
self.comps[N].position = [1,2,3,4]
将改变某些部分:
self.position[]