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

查看:473
本文介绍了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?

任何帮助将非常感谢!
注意:此问题是从此其他问题的分拆

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天全站免登陆