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

问题描述

我正在研究开发一个应用程序,该应用程序将以每秒 2000 行(帧)的速度处理来自线扫描相机的数据.对于这个实时应用,我觉得C/C++是要走的路.(这是我的感觉,其他人会同意托管代码不适合此任务.)

然而,我很少做过 MFC 或任何其他 C++ GUI.不过,我真的很擅长做 C# GUI.

所以对我来说,用 C/C++ 编写数据密集型代码和用 C# 编写 GUI 似乎很自然.GUI 将用于设置/校准/在线监控(并且可能通过 UDP 输出数据,因为它在 C# 中更容易.

所以首先,我想看看是否有人同意这是要走的路.根据我的编程经验(擅长低级 C 算法和高级 C# GUI 设计),感觉不错.

其次,我不确定正确的方法.我刚刚在 VS2005 中组合了一个解决方案,它从 C# 应用程序调用一些(externC")DLL 函数.为了确保我能做到,我在 DLL 中写入了一些全局变量,并从中读取:

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) {数据 = 数量;}__declspec(dllexport) int get() {返回数据;}

test.cs

[DllImport("test")]私有静态外部无效集(int num);[DllImport("test")]private static extern int get();

调用 get()set() 工作正常(get() 返回我传递给 set()).

现在,我知道您也可以导出 C++ 类,但是它必须被管理吗?这是如何运作的?我这样做对吗?

感谢您的帮助!

*** 编辑 ***

首先,感谢您到目前为止的精彩回答!我总是对 Stack Overflow 印象深刻...

我想我应该多注意一件事,不一定是原始速度(这可以进行原型设计和基准测试).让我更关心的一件事是垃圾收集器的非确定性行为.此应用程序在执行垃圾收集时不能容忍 500 毫秒的延迟.

我完全赞成在纯 C# 中进行编码和尝试,但是如果我提前知道 GC 和任何其他非确定性 .NET 行为 (?) 会导致问题,我认为我的时间会更好地度过用 C/C++ 编码并找出最好的 C# 接口.

解决方案

没有理由不能完全用 C# 编写高性能代码.

关于相同/相似主题的 SO 问题:

其他文章:

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

However, I've done very little MFC, or any other C++ GUI. I am really getting to do C# GUIs very well, though.

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

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.

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();

Calling get() and set() work properly (get() returns the number that I passed to set()).

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?

Thanks for all your help!

*** EDIT ***

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

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.

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.

解决方案

There is no reason that you can't write high performance code entirely in C#.

SO questions on the same/similiar topic:

Other articles:

这篇关于快速的 C++ 程序,C# GUI,可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 06:58
查看更多