简体   繁体   English

使用Process.Start运行C ++ exe与使用CLR包装C ++代码

[英]Running C++ exe using Process.Start versus wrapping the C++ code using CLR

I have a C++ executable which I need to integrate into my .NET app. 我有一个C ++可执行文件,需要将其集成到我的.NET应用程序中。 The C++ exe is a specialized calculator which will be invoked very frequently during lengthy processing of some large data. C ++ exe是一个专用的计算器,在长时间处理某些大数据期间将非常频繁地调用它。 For this, I need the integration to be as efficient as possible. 为此,我需要集成尽可能地高效。

In term of efficiency, is there any advantage of wrapping the C++ code into a CLR .dll which I can then use directly from my .NET app over just using Process.Stat and parsing the output stream? 就效率而言,将C ++代码包装到CLR .dll中是否有任何优势,我可以直接在.NET应用程序中使用它,而不仅仅是使用Process.Stat并解析输出流?

When you use Process.Start() it is creating a new application, allcation of memory and task scheduling is an overehead. 当您使用Process.Start()创建新应用程序时,分配内存和任务调度是一项开销。 given the fact that you are calling it many times, you should make it into a DLL and use the function. 考虑到您多次调用它,您应该将其放入DLL并使用该函数。 as the loaded DLL will always be in memory and run faster. 因为加载的DLL始终位于内存中,并且运行速度更快。

lets say that there is change in the parameter to the exe, you might not catch it soon enough, if it is packaged in a DLL then its more controlled. 可以说exe的参数有变化,如果将其打包在DLL中,则它可能会受到更大的控制,因此您可能不会很快捕获它。 contracts are stronger. 合同更强。

Launching a separate process involves creating a lot of overhead for that process and it's threads. 启动一个单独的进程涉及为该进程及其线程创建大量开销。 It also will be loaded/unloaded in memory every time. 每次也会在内存中加载/卸载它。 A dll could be loaded into memory once, and executed many times all on the main thread. 一个dll可以一次加载到内存中,并在主线程上执行多次。 So there is definitely efficiency to be gained by going the dll route. 因此,通过dll路由绝对可以提高效率。 Whether or not it's REALLY worth it is a trade-off between how much work it is to wrap it in the dll, and how much efficiency you will truly gain. 是否真正值得,这是在将它包装到dll中需要进行的工作量与您将真正获得的效率之间的平衡。

You said that it will be called frequently. 您说它将经常被调用。 If this means thousands of times, it will probably be worth putting into a dll. 如果这意味着成千上万次,则可能值得将其放入dll。 But really, measurement is the only way to know for sure how much difference it will make. 但实际上,测量是唯一确定将产生多大影响的唯一方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM