首页 > 解决方案 > 如何在 Python 中使用带有 ctypes.Strcuture 类的插槽?

问题描述

我正在使用 Python 2.7 编写一个应用程序,它将大量 3D 网格结构从一个应用程序导出到另一个应用程序。

由于大量 3D 数据,我定义了一个名为“Face”的类,如下代码所示,作为传递给 c-dll 的临时数据结构。

我的问题:如果我想用插槽保存内存,我该如何重新定义这个类?或者有没有其他方法可以有效地节省内存?


    class Face(ctypes.Structure):
        __slots__ = ()
        # __slots__ = ['A','B','C','vert_index','vert_index','edge_sm','sm_group','is_hidden','edge_hidden','mtl_index','uv']
        _fields_ = [
            ("A",               ctypes.POINTER(ctypes.c_double)),
            ("B",               ctypes.POINTER(ctypes.c_double)),
            ("C",               ctypes.POINTER(ctypes.c_double)),
            ("vert_index",      ctypes.POINTER(ctypes.c_int)),
            ("edge_sm",         ctypes.POINTER(ctypes.c_bool)),
            ("sm_group",        ctypes.c_int),
            ("is_hidden",       ctypes.c_bool),
            ("edge_hidden",     ctypes.POINTER(ctypes.c_int)),
            ("mtl_index",       ctypes.c_int),
            ("uv",              ctypes.POINTER(ctypes.c_double)),
        ]

感谢任何建议。谢谢。

标签: pythonpython-2.7

解决方案


推荐阅读