【问题标题】:How to get size of ctypes array on memory如何在内存中获取 ctypes 数组的大小
【发布时间】:2021-05-22 18:42:42
【问题描述】:

我在 python 中使用ctypes 库创建了一个数组。我想知道数组的大小(以字节为单位)。我试过sys.getsizeof()。无论我创建多大的数组,这个函数总是返回 120。

E = (10 * ctypes.py_object)()
for j in range(10):
    E[j] = 0
print(sys.getsizeof(E))
output: 120

【问题讨论】:

    标签: python python-3.x ctypes


    【解决方案1】:

    改用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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 2020-02-18
      • 1970-01-01
      • 2021-06-28
      • 2012-04-13
      • 2010-10-29
      • 2021-08-20
      相关资源
      最近更新 更多