何时对类和结构使用 __gc?
我正在更新一些旧的 C++ 代码,发现许多类定义为:
public __gc class NameOfClass{ }
我发现了一些有关 __gc 这里,但它似乎只提供了 VS 2003 的信息。我的 VS 2005 副本附带的 MSDN 文档表明 __gc可能不再使用。
我自己就是一名 C# 人员,所以我想确保在更新此代码时不会犯错误。 .NET 2.0 及更高版本中的 C++ 类的垃圾收集是否自动进行?或者 __gc 关键字是否已以某种方式被替换?
I am updating some old c++ code and am finding that many of the classes are defined as:
public __gc class NameOfClass{ }
I found a little bit of information about __gc here, but it seems to only come up with information for VS 2003. The MSDN documentation that came with my copy of VS 2005 indicates that __gc may not be in use anymore.
I'm a C# guy myself, so I want to make sure I don't make a mistake when updating this code. Is garbage collecting automatic for c++ classes in .NET 2.0 and greater? Or has the __gc keyword been replaced in some way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在查看具有托管扩展的 C++,这是使用一些相当有创意的语法向 cpp 添加 clr 功能的简短但失败的尝试。我相信从 2005 年开始,c++ cli 得到了全面支持,这是 clr 在 C++ 中的完整实现。请查看此内容,了解来自米。
You are looking at C++ with managed extensions which was a brief and failed attempt to add clr functionality to cpp using some rather inventive syntax. I believe from 2005 onward c++ cli was fully supported which is a full implementation of the clr in C++. Take a look at this for migrating advice from m.
它已被部分(可能完全)取代;我相信 BC 仍然支持它,但是 VS2005 引入了一种新机制,使托管类型更加明确。请参阅:http://msdn.microsoft.com /en-us/library/xey702bw%28v=VS.80%29.aspx
作为参考,旧语法的一个大问题是它添加了标准 C++ 语法的重载用法,这依赖于底层类型,这在代码中非常混乱。新语法可以更好地区分托管句柄和非托管指针。
It has been somewhat (possibly entirely) replaced; I believe it's still supported for BC, but there was a new mechanism introduced with VS2005 which made managed types more explicit. See: http://msdn.microsoft.com/en-us/library/xey702bw%28v=VS.80%29.aspx
For reference, the big problem with the old syntax was that it added overloaded usage of standard C++ syntax, which was dependent on the underlying types, which was horribly confusing in code. The new syntax is much better for differentiating managed handles from unmanaged pointers.