快速的C ++程序,C#GUI,可能吗? [英] Fast C++ program, C# GUI, possible?

查看:172
本文介绍了快速的C ++程序,C#GUI,可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我寻找到开发将在每秒约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.)

不过,我已经做了的非常小MFC或任何其他的C ++图形用户界面。我真是越来越做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#应用程序调用一些(外部的C)的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 **/
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(),然后设置()工作正常(得到回报,我通过设置数字())。

Calling get() and then 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 ***

首先,谢谢的您梦幻般的答案为止!我总是用计算器...

First of all, THANK YOU for your fantastic answers so far! I'm always incredibly impressed with StackOverFlow...

我想一件事,我应该有更多的打,不一定是原始速度(这可以通过原型基准) 。有我更关心的一件事是垃圾回收器的不确定性的行为。该应用程序会的的在执行垃圾收集宽容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#接口。

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#.

波多黎各马里亚尼的性能博客(一个很好的资源)

调整.NET应用程序性能

等相同/ similiar主题的问题:

SO questions on the same/similiar topic:

  • C++ performance vs. Java/C#
  • How much faster is c++ than c#?

其他文章:

  • 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屋!

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