将结构传递到接口字段分配? [英] Does passing a struct into an interface field allocate?

查看:146
本文介绍了将结构传递到接口字段分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结构,这样的事情

I have a structure something like this

struct MyStructure
    :IFoo
{
}

和这样的方法:

public BarThisFoo(IFoo a)
{

}

$> b
$ b

我的问题是不通过构造成法盒子的结构,从而导致垃圾分配

my question is does passing the structure into that method "box" the structure, thus causing a garbage allocation?

附录:$? b $ b前面的人说,垃圾收集不在此应用程序免费的,它实际上是垃圾收集非常敏感,因此自由分配的代码是很重要的。

Addendum: Before anyone says it, garbage collection is not free in this application, it's actually very sensitive to garbage collections, so allocation free code is important.

推荐答案

是的,它的作用。


  • 的值类型的对象引用

  • 值类型:拳击每当从转换发生到 System.ValueType 引用

  • 的值类型由值类型实现的接口的引用

  • 枚举类型到 System.Enum 引用

  • a value type to an object reference
  • a value type to a System.ValueType reference
  • a value type to a reference to an interface implemented by the value type
  • an enum type to a System.Enum reference

这是三的情况下,很明显。你可以阅读更彻底的例子这里

This is case III, obviously. You can read a more thorough example here.

这篇关于将结构传递到接口字段分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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