Windows编程中的智能指针
排除STL,我只在C++ windows编程中找到了CComPtr。 Windows SDK中还有其他类型的智能指针吗?谢谢。
Excluding STL, I only found CComPtr in C++ windows programming. Is there any other types of smart pointers in windows SDK? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,STL 和 boost 的智能指针在 Windows 上可用,使用它们没有任何问题。
说到纯粹的 Windows 东西,COM 接口指针及其 AddRef/Release 生命周期管理模型很容易成为智能指针。 Windows 特定的库中有一些智能指针类专门用于存储 COM 接口指针。除了 ATL 的 CComPtr<> 之外,还有 _com_ptr_t<> 。 Microsoft Native COM 和 MFC 的 COleDispatchDriver。随着 Native COM 的出现,后者几乎不再被使用。除了 CComPtr 之外,它们都与类型库导入工具一起使用。
First, STL's and boost's smart pointers are available on Windows and there's nothing wrong with using those.
Speaking of purely Windows stuff, COM interface pointers, with their AddRef/Release lifetime management model, readily lends itself to smart pointers. There are some smart pointer classes in Windows-specific libraries that are geared towards storing COM interface pointers. In addition to the ATL's CComPtr<>, there's _com_ptr_t<> of Microsoft Native COM, and MFC's COleDispatchDriver. The latter is hardly ever used with the advent of Native COM. With the exception of CComPtr, those are used together with type library import facilities.
在Windows SDK(特定于ATL)中,有CAutoPtr(单项分配)和CAutoVectorPtr(数组分配)。
In the Windows SDK (specific to ATL), there is CAutoPtr(single item allocation) and CAutoVectorPtr (array allocation).
MSDN 文章 指出 CComPtr 是设计为仅与 COM 对象一起使用。一般来说,Boost智能指针通常用作平台 -独立的C++智能指针库。由于智能指针的概念并不绑定到特定的操作系统,因此实际上没有必要使用绑定到 Windows 的智能指针实现,即使这是您计划开发应用程序的唯一平台。
The MSDN article states that CComPtr is designed to be used with COM objects only. Generally Boost smart pointers are commonly used as a platform-independent C++ smart pointer library. Since the concept of smart pointers isn't bound to a particular OS, there's really no need to use a smart pointer implementation bound to Windows, even if that's the only platform you plan on developing the application for.