快C ++程序,C#GUI,可能吗? [英] Fast C++ program, C# GUI, possible?
问题描述
我正在研究开发一种应用程序,该应用程序将以每秒2000行(帧)的线扫描相机处理数据。对于这个实时应用程序,我觉得C / C ++是要走的路。 (这是我的感觉,其他人会同意托管代码对于这个任务是不正确的。)
I'm looking into developing an application that will process data from a line-scan camera at around 2000 lines (frames) per second. For this real-time application, I feel that C/C++ are the way to go. (It is my feeling, and others will agree that Managed code just isn't right for this task.)
然而,我已经做了 em>小MFC或任何其他C ++ GUI。我真的很喜欢做C#GUI,但是。
However, I've done very little MFC, or any other C++ GUI. I am really getting to do C# GUIs very well, though.
所以在C / C ++中编写数据密集型代码,而GUI C#。 GUI将用于设置/校准/在线监控(并且可能通过UDP输出数据),因为在C#中更容易。
So it seems natural to me to write the data-intensive code in C/C++, and the GUI in C#. The GUI will be used for set-up/calibration/on-line monitoring (and possibly outputting of data via UDP, because it's easier in C#.
首先,我根据我的编程经验(擅长于低级别的C语言算法和高级别的C#GUI设计),只是觉得很正确。
So first, I'd like to see if anyone agrees that this would be the way to go. Based on my programming experience (good at low-level C algorithms, and high-level C# GUI design), it just feels right.
其次,我不确定正确的方法,我刚刚在VS2005中提出了一个解决方案,它从C#应用程序中调用了一些(externC)DLL函数。为了确保我可以做到这一点,我写了一些DLL中的全局变量,并从他们那里读取:
Secondly, I'm not sure the right way to go about it. I just threw together a solution in VS2005, which calls some (extern "C") DLL functions from a C# app. And to make sure I could do it, I wrote to some global variables in the DLL, and read from them:
test.h / p>
test.h
int globaldata;
extern "C" __declspec(dllexport) void set(int);
extern "C" __declspec(dllexport) int get();
test.cpp
extern int data=0;
__declspec(dllexport) void set(int num) {
data = num;
}
__declspec(dllexport) int get() {
return data;
}
test.cs
[DllImport("test")]
private static extern void set(int num);
[DllImport("test")]
private static extern int get();
调用 get()
和 set()
正常工作( get()
返回我传递给 set()
)。
Calling get()
and set()
work properly (get()
returns the number that I passed to set()
).
现在,我知道你可以导出一个C ++类,但是它必须被管理?这是如何工作的?我正在这样做吗?
Now, I know that you can export a C++ class as well, but does it have to be managed? How does that work? Am I going about this the right way?
感谢您的帮助!
***编辑***
*** EDIT ***
首先,谢谢你为您的梦幻般的答案到目前为止!我总是对Stack Overflow感到非常深刻的印象...
First of all, THANK YOU for your fantastic answers so far! I'm always incredibly impressed with Stack Overflow...
我想有一件事我应该打更多,不一定是原始速度(这可以是原型和基准)。我更关心的一件事是垃圾收集者的非确定性行为。这个应用程序将在执行垃圾收集时不会容忍500ms的延迟。
I guess one thing I should have hit on more, was not necessarily raw speed (this can be prototyped and benchmarked). One thing that has me more concerned is the non-deterministic behavior of the Garbage Collector. This application would not be tolerant of a 500ms delay while performing garbage collection.
我正在为纯C#进行编码和尝试,但是如果我提前知道GC和任何其他非确定性.NET行为(?)会导致问题,我认为我的时间会更好地用C / C ++编码,并找出最好的C#界面。 p>
I am all for coding and trying this in pure C#, but if I know ahead of time that the GC and any other non-deterministic .NET behavior (?) will cause a problem, I think my time would be better spent coding it in C/C++ and figuring out the best C# interface.
推荐答案
没有任何理由不能完全在C#中编写高性能代码
There is no reason that you can't write high performance code entirely in C#.
Rico Mariani的表演博客(一个很好的资源)
相同/类似主题的问题:
SO questions on the same/similiar topic:
- C++ performance vs. Java/C#
- How much faster is c++ than c#?
其他文章:
- Microbenchmarking C ++,C#和Java
- 利用C#为您的科学计算项目提供支持的功能
- 使用Visual Studio Profiler查找应用程序瓶颈
- Debunking C#vs C ++ Performance
- Microbenchmarking C++, C#, and Java
- Harness the Features of C# to Power Your Scientific Computing Projects
- Find Application Bottlenecks with Visual Studio Profiler
- Debunking C# vs C++ Performance
这篇关于快C ++程序,C#GUI,可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!