BSTR 和 _bstr_t 有什么区别? [英] What's the difference between BSTR and _bstr_t?

查看:24
本文介绍了BSTR 和 _bstr_t 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释上面提到的类型之间的区别以及一些示例用法以清楚地解释两者之间的区别?

Can anyone explain the difference between the types mentioned above and some sample usage to clearly explain the difference between the two?

任何帮助将不胜感激!注意:这个问题是 this other question

Any help would be highly appreciated! Note: this question is a spin-off from this other question

推荐答案

BSTR 是 COM 使用的字符串数据类型.

BSTR is the string data type used with COM.

_bstr_t 是一个像智能指针一样工作的包装类,因此当变量被销毁或超出范围时,它将释放分配的内存._bstr_t 还具有引用计数,每次按值传递 _bstr_t 变量时都会增加(避免不必要的复制),并在不再使用时减少.每当所有引用都被销毁时,为字符串分配的内存就会被释放.

_bstr_t is a wrapper class that works like a smart pointer, so it will free the allocated memory when the variable is destroyed or goes out of scope. _bstr_t also has reference counting, which increases every time you pass the _bstr_t variable by value (avoiding unnecessary copy) and decrement when it is no longer used. Whenever all references are destroyed, the allocated memory for the string is freed.

BSTR 的替代品是 CComBSTR.它还管理 BSTR 的内存,但没有引用计数.

An alternative to BSTR is the CComBSTR. It also manages the memory for the BSTR, but has no reference counting.

这篇关于BSTR 和 _bstr_t 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆