Code-Portability
-
Hi everybody! Last week I received the task to develop and implement a simulation and analysis environment for a flow control algorithm. I have no restrictions for this except that the flow control algorithm will be implemented in C++. Because i recently worked much with C# and really like it, i want to use this instead of C++. But this of course brings up the question of how to insert the algorithm into the environment.? How good are the chances to port this algorithm to C# and are there maybe some existing tools? Otherwise, i thought of creating a .NET Class Library with the algorithm and use this in my C#-Code, because i've read it's no problem to mix programming languages that way.? Can someone tell me if it's possible what i want to do or give me some suggestions. Thx in advance!
-
Hi everybody! Last week I received the task to develop and implement a simulation and analysis environment for a flow control algorithm. I have no restrictions for this except that the flow control algorithm will be implemented in C++. Because i recently worked much with C# and really like it, i want to use this instead of C++. But this of course brings up the question of how to insert the algorithm into the environment.? How good are the chances to port this algorithm to C# and are there maybe some existing tools? Otherwise, i thought of creating a .NET Class Library with the algorithm and use this in my C#-Code, because i've read it's no problem to mix programming languages that way.? Can someone tell me if it's possible what i want to do or give me some suggestions. Thx in advance!
Troschi wrote: Otherwise, i thought of creating a .NET Class Library with the algorithm and use this in my C#-Code A .NET Class Library is written in any language targeting the CLR, like C#. You could implement this in C#, yes, but .NET itself is not a language - it's a Framework comprised of the Common Language Runtime (CLR), the Common Type System (CTS), and the Common Interface Language (CIL). If you need to implement the algorithm in C++, consider using the Managed C++ extensions and write it using a mixed-mode assembly. Any language targeting the CLR (like C#, VB.NET, et. al.) can use it like any other assembly written in any other language (it all compiles down to Microsoft Intermediate Language, or MSIL anyway, though native instructions in C/C++ are compiled to native code, making your assembly less portable). You seem to be a little confused about what .NET is. I suggest you read about the Microsoft .NET Framework[^] to learn more.
Microsoft MVP, Visual C# My Articles
-
Troschi wrote: Otherwise, i thought of creating a .NET Class Library with the algorithm and use this in my C#-Code A .NET Class Library is written in any language targeting the CLR, like C#. You could implement this in C#, yes, but .NET itself is not a language - it's a Framework comprised of the Common Language Runtime (CLR), the Common Type System (CTS), and the Common Interface Language (CIL). If you need to implement the algorithm in C++, consider using the Managed C++ extensions and write it using a mixed-mode assembly. Any language targeting the CLR (like C#, VB.NET, et. al.) can use it like any other assembly written in any other language (it all compiles down to Microsoft Intermediate Language, or MSIL anyway, though native instructions in C/C++ are compiled to native code, making your assembly less portable). You seem to be a little confused about what .NET is. I suggest you read about the Microsoft .NET Framework[^] to learn more.
Microsoft MVP, Visual C# My Articles
Thanks for answering. I know .Net is not a language. Maybe i didn't express myself well by using the term ".NET Class Library". I meant creating a Class Library targeting the CLR which is written in C++. Anyway, it's good to know that i can use it in languages targeting the CLR. As i said i read about it but never used it until now. Just wanted to be sure it works. Also i will read more about .NET Framework, always had this in mind but never found the time. Nevertheless I have another question. I don't write the flow control algorithm myself, just the simulation and analysis environment. Therefor I have no real influence on the implementation of the algorithm. I'm a bit afraid that when i want to create the .Net Class Library with the completed algorithm some bad difficulties, incompabilities or so occur. I don't really know how to say this. Any guideline to avoid such things? Hope i could make myself clear.
-
Thanks for answering. I know .Net is not a language. Maybe i didn't express myself well by using the term ".NET Class Library". I meant creating a Class Library targeting the CLR which is written in C++. Anyway, it's good to know that i can use it in languages targeting the CLR. As i said i read about it but never used it until now. Just wanted to be sure it works. Also i will read more about .NET Framework, always had this in mind but never found the time. Nevertheless I have another question. I don't write the flow control algorithm myself, just the simulation and analysis environment. Therefor I have no real influence on the implementation of the algorithm. I'm a bit afraid that when i want to create the .Net Class Library with the completed algorithm some bad difficulties, incompabilities or so occur. I don't really know how to say this. Any guideline to avoid such things? Hope i could make myself clear.
If you can't dictate how the algorithm is developed, don't fret. You have several options: create a MC++ assembly that uses the C/C++ APIs even in a
__gc
class (managed class declaration). Compile it as an assembly and you'll have no problems. If the algorithm is comprised of only a few exported functions (hopefully C-style, but C++ name mangling is not really a problem either), then consider writing your wrapper component in C# and just P/Invoke the functions you need, correctly defining any structs and consts you might need to marshal.Microsoft MVP, Visual C# My Articles