ctypes中不同版本的msvcrt

发布于 2024-08-03 19:58:08 字数 607 浏览 4 评论 0 原文

在 Windows 中,当我导入 ctypes 模块时,ctypes.cdll.msvcrt 对象会自动存在,它代表 msvcrt Microsoft C++ 运行时库 根据文档

但是,我注意到还有一个 find_msvcrt 函数,它将“返回Python使用的VC运行类型库的文件名”

它进一步指出,“如果您需要释放内存,例如,由扩展模块通过调用 free(void *) 分配的内存,那么在分配内存的同一库中使用该函数非常重要。”

所以我的问题是,我已有的 ctypes.cdll.msvcrt 库与我可以使用 find_msvcrt 加载的库之间有什么区别?功能?在什么特定情况下它们可能不是同一个库?

In Windows, the ctypes.cdll.msvcrt object automatically exists when I import the ctypes module, and it represents the msvcrt Microsoft C++ runtime library according to the docs.

However, I notice that there is also a find_msvcrt function which will "return the filename of the VC runtype library used by Python".

It further states, "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."

So my question is, what's the difference between the ctypes.cdll.msvcrt library that I already have and the one which I can load with the find_msvcrt function? Under what specific circumstances might they not be the same library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一口甜 2024-08-10 19:58:08

不仅ctypes.cdll.msvcrt自动存在,而且ctypes.cdll.anything自动存在,并且在第一次访问时加载,加载anything.dll< /代码>。因此,ctypes.cdll.msvcrt 加载 msvcrt.dll,它是作为 Windows 一部分提供的库。 Python 链接的不是 C 运行时,因此您不应从 msvcrt 调用 malloc/free。

例如,对于 Python 2.6/3.1,您应该使用 ctypes.cdll.msvcr90。由于这会随着时间的推移而改变,find_msvcrt()< /code> 为您提供应该真正使用的库的名称(然后通过 ctypes.CDLL)。

以下是 Microsoft CRT 的几个不同版本的名称,它们作为 MSC、VC++、平台 SDK 或 Windows 的一部分在不同时间点发布:crtdll.dll、msvcrt.dll、msvcrt4.dll、msvcr70.dll、msvcr71。 dll、msvcr80.dll、msvcr90.dll。

It's not just that ctypes.cdll.msvcrt automatically exists, but ctypes.cdll.anything automatically exists, and is loaded on first access, loading anything.dll. So ctypes.cdll.msvcrt loads msvcrt.dll, which is a library that ships as part of Windows. It is not the C runtime that Python links with, so you shouldn't call the malloc/free from msvcrt.

For example, for Python 2.6/3.1, you should be using ctypes.cdll.msvcr90. As this will change over time, find_msvcrt() gives you the name of the library that you should really use (and then load through ctypes.CDLL).

Here are the names of a few different versions of the Microsoft CRT, released at various points as part of MSC, VC++, the platform SDK, or Windows: crtdll.dll, msvcrt.dll, msvcrt4.dll, msvcr70.dll, msvcr71.dll, msvcr80.dll, msvcr90.dll.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文