调用可执行文件与调用代码c#,c ++ [英] Calling an Executable vs Calling in Code c#, c++

查看:90
本文介绍了调用可执行文件与调用代码c#,c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其他一个工作团队有一个网络服务器执行一些C#代码。他们在C ++中有一些其他代码,它们被编译成可执行的exe文件。使用C#代码,他们在代码中执行exe函数并传递参数。他们确实有c ++代码的源代码,他们不想在CLR中混合使用c ++和c#,或者不知道如何使用。



我的问题是这样做有任何不利之处,包括在CLR函数中包含c ++代码并调用代码。是否有任何额外的内存丢失等因为在Web服务器中调用可执行文件?



这个特定的c ++代码每个用户每1小时被调用至少200次。我估计只有100个用户才能访问该网页。总共20000每小时。

One of the other teams at work has a webserver executing some C# code. They have some other code in C++ which they compiled into an executable exe file. Using the C# code they execute the exe function in the code and pass arguments. They do have the source code for the c++ code and they didn't want to mix c++ and c# in CLR or did not know how to.

My question is whether there is any disadvantage in doing this versus including the c++ code in a CLR function and calling the code. Is there any extra memory loss etc because of calling an executable in the web server?

This particular c++ code gets called at least 200 times every 1 hour per user. I estimate that there about 100 users only for the webpage. So total of 20000 per hour.

推荐答案

使用EXE的缺点是如此严重,以至于你应该一定避免使用这个选项。 解决方案#1提供了最糟糕的建议。它意味着单独的流程,流程是高度孤立的。使用EXE的唯一好处是通过命令行简单地使用一些简单的第三方实用程序(通常只有控制台),但这不是你的情况。



您可以使用纯CLI代码,也可以使用P / Invoke来管理托管中的本机代码:

http://en.wikipedia.org/wiki/P/invoke [ ^ ],

http://www.xinterop.com [ ^ ]。



此CodeProject文章也很有用: http://www.codeproject.com/csharp/EssentialPInvoke.asp [ ^ ]。



另一种选择是使用C ++ / CLI。您可以创建混合模式项目(托管+非托管)。从CLR的角度来看,这是一个常规的.NET程序集,可以被其他程序集正常使用。同时,它可以包含非托管代码,您可以将其包装在refCLI类中以将它们公开给.NET。



-SA
The disadvantages of using EXE is so serious that you should avoid this option by all means. "Solution" #1 provides the worst advice. It means separate processes, and processes are highly isolated. The only benefit of using EXE is the simplicity of the use of some simple 3rd-party utilities (usually console-only) via a command line, but this is not your case.

You can have pure CLI code, or you can use native code in managed by using P/Invoke:
http://en.wikipedia.org/wiki/P/invoke[^],
http://www.xinterop.com[^].

This CodeProject article can also be useful: http://www.codeproject.com/csharp/EssentialPInvoke.asp[^].

Another option is using C++/CLI. You can create a mixed-mode project (managed+unmanaged). From the CLR standpoint, this is a regular .NET assembly which can be use normally by other assemblies. At the same time, it can contain unmanaged code which you can wrap in "ref" CLI classes to expose them to .NET.

—SA


我可能会去c ++ exe选项 - 因为基本上它可以工作所以请不要管它:)



你可能可以将c ++代码移植到c#并从你的应用程序中调用它,而不是启动那个exe,但我不知道如果你的服务器正在处理一切就值得努力



如果你将exe移植到c#或其他什么,那么你也有测试的开销,以确保你没有塞满任何东西。



布莱斯
I'd probably go the c++ exe option - because basically it works so leave it alone :)

you can probably port the c++ code to c# and call it from within your app as opposed to starting that exe, but i dunno if its worth the effort if your server is handling everything ok

If you port the exe to c# or whatever then you also have the overhead of testing to make sure you haven't stuffed anything up.

Bryce


ok - 有效吗?



a)是



我的选择是不管它 - 理论是如果没有破坏不解决它



布莱斯
ok - does it work?

a) yes

My choice would be to leave it alone - the theory being if it ain't broke dont fix it

Bryce


这篇关于调用可执行文件与调用代码c#,c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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