在同一进程中的 .Net AppDomain 之间进行通信的底层机制是什么?
我意识到理性的下意识反应是“远程处理你这个白痴!阅读 MSDN 文档”。 我能找到的关于 .Net Remoting 的每一条信息都是在进程间通信的背景下进行的:套接字、共享内存、管道……这些都是 IPC 的经典,但 AppDomain 并不是真正的进程。 然而,AppDomains 似乎享受到了成为其中之一的大部分好处。 从学术角度来看,与驻留在同一进程中的实体之间的通信相比,操作系统 IPC 原语更加繁重。 当通信跨越同一进程内的 AppDomain 边界时是否使用特殊的 AppDomain 管道? 我对此表示怀疑。 如果 MS 改变 Windows 内核中进程隔离的基本原理以适应 AppDomain,我会感到震惊。
I realize a rational knee-jerk response would be "Remoting you idiot! Read the MSDN docs." Every scrap of info I can find concerning .Net Remoting is in the context of inter-process communication: sockets, shared memory, pipes...the classics when it comes to IPC, but an AppDomain is not really a process. However, AppDomains seem to enjoy most of the benefits of being one. From an academic perspective, OS IPC primitives are heavy compared to communication between entities that reside in the same process. Is there a special AppDomain pipe that is used when communication crosses an AppDomain boundary within the same process? I doubt it. I would be shocked if MS changed the fundamentals of process isolation within the Windows kernel to accommodate AppDomains.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下有一条快速路径。 不需要进程间通信,因为应用程序域位于同一进程中,并且 CLR 可以完全访问所有应用程序域和完整的地址空间。 它实际上只是调用堆栈中的一些标记,用于安全和异常处理目的以及应用程序域提供的可卸载性。
There's a fast path in this case. There is no need for interprocess communication, since the appdomains live in the same process and the CLR has full access to all of them and the full address space. It's really just some markers in the call stack for security and exception handling purposes as well as the unloadability that appdomains give.
您的问题的旁注,或者更多的历史脚注。 这并不是全新的,COM 在线程之间的封送接口方面有一些相似的语义:一个线程将使用 CoMarshalInterThreadInterfaceInStream 然后另一个线程将使用 CoGetInterfaceAndReleaseStream。
A side note to your question, or more of a history foot note. This is not entirely new, COM had somewhat similar semantics in marshaling interfaces between threads: one thread would marshal the interface into a stream using CoMarshalInterThreadInterfaceInStream and then the other thread would extract the intrface form the stream using CoGetInterfaceAndReleaseStream.
进程内的 AppDomain 之间进行通信的基本方式确实是远程处理。 这允许对象驻留在一个 AppDomain 中,并让其他对象通过另一个域中的透明代理通过该对象进行通信。
是的,AppDomain 并不是真正的进程,但最好将它们设想为非常轻量级的进程。
The fundamental way to communicate between AppDomains within a process is indeed remoting. This allows an object to live in one AppDomain and have others communicate through it via a transparent proxy in another domain.
Yes AppDomains are not really a process but they are best envisioned as very light weight processes.