在Windows中,当我导入ctypes模块时,ctypes.cdll.msvcrt对象会自动存在,并且它表示msvcrt微软C++运行时库according to the docs。
但是,我注意到还有一个将执行"return the filename of the VC runtype library used by Python"的find_msvcrt函数。
它进一步声明,"If you need to free memory, for example, allocated by an extension module with a call to the free(void *), it is important that you use the function in the same library that allocated the memory."
所以我的问题是,我已经拥有的ctypes.cdll.msvcrt库和我可以用find_msvcrt函数加载的库有什么不同?在什么特定情况下,它们可能不是同一个库?
发布于 2009-08-28 19:30:12
不仅仅是ctypes.cdll.msvcrt会自动存在,ctypes.cdll.anything也会自动存在,并在第一次访问时加载,加载anything.dll。因此,ctypes.cdll.msvcrt会加载msvcrt.dll,这是一个作为Window一部分提供的库。它不是Python链接的C运行时,所以您不应该从msvcrt调用malloc/free。
例如,对于Python2.6/3.1,您应该使用ctypes.cdll.msvcr90。由于这种情况会随着时间的推移而改变,因此find_msvcrt()会给出您真正应该使用的库的名称(然后通过ctypes.CDLL加载)。
以下是几个不同版本的Microsoft CRT的名称,作为MSC、VC++、platform SDK或Windows的一部分在不同的地方发布: crtdll.dll、msvcrt.dll、msvcrt4.dll、msvcr70.dll、msvcr71.dll、msvcr80.dll、msvcr90.dll。
https://stackoverflow.com/questions/1348547
复制相似问题