我在python中使用ctypes
库创建了一个数组。我想知道数组的大小(以字节为单位(。我试过sys.getsizeof()
。无论我创建的数组有多大,这个函数总是返回120。
E = (10 * ctypes.py_object)()
for j in range(10):
E[j] = 0
print(sys.getsizeof(E))
output: 120
改用ctypes.sizeof
:
import ctypes
E = (10 * ctypes.py_object)()
for j in range(10):
E[j] = 0
print(ctypes.sizeof(E))
https://docs.python.org/3.8/library/ctypes.html#ctypes.sizeof