def test_cpy_arr(self): arr = array("f") arr.append(5) arr.append(9) arr2 = array("f") arr2.append(59) arr2.append(79) sa, nelem = arr.buffer_info() da, nelem2 = arr2.buffer_info() memcpy(da, sa, 8) self.assertAlmostEqual(arr[0], arr2[0]) self.assertAlmostEqual(arr[1], arr2[1])
def test_cpy_arr(self): arr = array('f') arr.append(5) arr.append(9) arr2 = array('f') arr2.append(59) arr2.append(79) sa, nelem = arr.buffer_info() da, nelem2 = arr2.buffer_info() memcpy(da, sa, 8) self.assertAlmostEqual(arr[0], arr2[0]) self.assertAlmostEqual(arr[1], arr2[1])
def add_default_instances(self, n): #TODO improve performnase of this! for k in range(n): if self.address is None: self.address = x86.MemData(self.sizeof) self.reserve += 1 elif self.reserve == self.size: if self.size > 0 and self.size <= 100: self.reserve += 1 elif self.size > 100 and self.size <= 10000: self.reserve += 100 elif self.size > 10000 and self.size <= 1000000: self.reserve += 10000 else: self.reserve += 100000 temp = x86.MemData(self.sizeof * self.reserve) memcpy(temp.ptr(), self.address.ptr(), self.size * self.sizeof) self.address = temp offset = self.sizeof * self.size x86.SetData(self.address.ptr() + offset, self.bytes) self.size += 1
def add_instance(self, instance): if self.address is None: self.address = x86.MemData(self.sizeof) self.reserve += 1 elif self.reserve == self.size: if self.size > 0 and self.size <= 100: self.reserve += 1 elif self.size > 100 and self.size <= 10000: self.reserve += 100 elif self.size > 10000 and self.size <= 1000000: self.reserve += 10000 else: self.reserve += 100000 temp = x86.MemData(self.sizeof * self.reserve) memcpy(temp.ptr(), self.address.ptr(), self.size * self.sizeof) self.address = temp offset = self.sizeof * self.size x86.SetData(self.address.ptr() + offset, self.bytes) for key, value in instance.items(): self._set_member(key, value, self.size) self.size += 1
def add_default_instances(self, n): # TODO improve performnase of this! for k in range(n): if self.address is None: self.address = x86.MemData(self.sizeof) self.reserve += 1 elif self.reserve == self.size: if self.size > 0 and self.size <= 100: self.reserve += 1 elif self.size > 100 and self.size <= 10000: self.reserve += 100 elif self.size > 10000 and self.size <= 1000000: self.reserve += 10000 else: self.reserve += 100000 temp = x86.MemData(self.sizeof * self.reserve) memcpy(temp.ptr(), self.address.ptr(), self.size * self.sizeof) self.address = temp offset = self.sizeof * self.size x86.SetData(self.address.ptr() + offset, self.bytes) self.size += 1