如何获取内存中 ctypes 数组的大小

How to get size of ctypes array on memory

我使用 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