5

I have a case where I have to use some classes across AppDomains. To make them work I have them inheriting from MarshalByRefObject. Everything with these classes work as expected. But these classes are used throughout our system, and 99% of the time these classes will be used within only one AppDomain. Are there any negative side effects from inheriting from MarshalByRefObject when using these classes within a single AppDomain?

Thanks,
Skip

4

1 回答 1

9

当然,MRBO 对抖动生成的代码有很大的影响。对类的字段的任何访问都会导致调用在 CLR 中实现的辅助方法,而不是访问该字段的单个 CPU 指令。

这是不可避免的,只有 CLR 知道对象实际上是代理还是真正的交易。并且代理需要模拟一个带有远程调用的字段。如果它不是代理,那么您仍然需要为辅助调用开销付费,这要慢一个数量级。

无法预测这是否真的对您的代码有影响,我们在这里谈论的是纳秒。只有当减速变得明显时,你才会做一些事情。

于 2013-09-20T21:09:26.733 回答