开发者

Who takes care of freeing MIB_TCPROW_OWNER_PID structure when calling GetExtendedTcpTable via ctypes in Python?

I'm calling GetExtendedTcpTable via ctypes in Python.

For this I'm declaring the following structures:

  开发者_JAVA技巧  class MIB_TCPROW_OWNER_PID(ctypes.Structure):
    _fields_ = [('dwState', DWORD),
                ('dwLocalAddr', DWORD),
                ('dwLocalPort', DWORD),
                ('dwRemoteAddr', DWORD),
                ('dwRemotePort', DWORD),
                ('dwOwningPid', DWORD)]

And:

    class MIB_TCPTABLE_OWNER_PID(ctypes.Structure):
    _fields_ = [('dwNumEntries', DWORD),
                ('table', MIB_TCPROW_OWNER_PID * ANY_SIZE)]

Where ANY_SIZE is initialized via a first call to GetExtendedTcpTable.

My question is who takes care of deallocating the memory taken by the 'table' field above? Which is an Array of MIB_TCPROW_OWNER_PID structures.

Or maybe my question should be: who allocates the MIB_TCPROW_OWNER_PID structures in the array? GetExtendedTcpTable or Python?

Thanks in advance!


You have to allocate sufficient space in table before calling GetExtendedTcpTable. And then when that call returns you need to deallocate it, although ctypes will do that for you.

If you have obtained ANY_SIZE by calling GetExtendedTcpTable with pTcpTable as NULL then you have nothing special to do. You create an instance of MIB_TCPTABLE_OWNER_PID and sufficient buffer is created for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜