473,396 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C++ wrap to C# efficiency

Hi,

I have some C++ static library which I would like to wrap and use in C#
applications. It appears that I have two options.

1. Wrap the static library as dynamic library (dll), use unmanaged C++. Then
invoke the method in C# by DllImport.

2. Wrap the static lib using managed C++, which will create a dll as .NET
assembly, so C# project can directly use it as reference and call methods
directly.

Not good as C++, if my understanding on approaches is correct, would the
first approach create faster execution for the same function since it is
mostly wrapped by "old faster C++" codes?
Thanks for help

Chris
Jul 23 '07 #1
2 2540
Chris,

Well, calling the library using managed C++ is going to be faster, as
you are not going through the P/Invoke layer, you will be making the call
natively (known as "it just works" or IJW). However, depending on how your
code is called, I would be inclined to say that this falls in the realm of
micro-optimization, and I would be more worried about getting the calls to
work first than optimizing on this level.

Now, if the calls to the functions in the library require some pretty
complex structure manipiulation, then I would say that this facilitates
creating the wrapper in C++, as it is better suited for this work. If you
are passing simple structure types, or even primitive types, then I would
say just do the wrapping into a DLL and make the calls through the P/Invoke
layer.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"chrisben" <ch******@discussions.microsoft.comwrote in message
news:C5**********************************@microsof t.com...
Hi,

I have some C++ static library which I would like to wrap and use in C#
applications. It appears that I have two options.

1. Wrap the static library as dynamic library (dll), use unmanaged C++.
Then
invoke the method in C# by DllImport.

2. Wrap the static lib using managed C++, which will create a dll as .NET
assembly, so C# project can directly use it as reference and call methods
directly.

Not good as C++, if my understanding on approaches is correct, would the
first approach create faster execution for the same function since it is
mostly wrapped by "old faster C++" codes?
Thanks for help

Chris

Jul 23 '07 #2
thanks

"Nicholas Paldino [.NET/C# MVP]" wrote:
Chris,

Well, calling the library using managed C++ is going to be faster, as
you are not going through the P/Invoke layer, you will be making the call
natively (known as "it just works" or IJW). However, depending on how your
code is called, I would be inclined to say that this falls in the realm of
micro-optimization, and I would be more worried about getting the calls to
work first than optimizing on this level.

Now, if the calls to the functions in the library require some pretty
complex structure manipiulation, then I would say that this facilitates
creating the wrapper in C++, as it is better suited for this work. If you
are passing simple structure types, or even primitive types, then I would
say just do the wrapping into a DLL and make the calls through the P/Invoke
layer.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"chrisben" <ch******@discussions.microsoft.comwrote in message
news:C5**********************************@microsof t.com...
Hi,

I have some C++ static library which I would like to wrap and use in C#
applications. It appears that I have two options.

1. Wrap the static library as dynamic library (dll), use unmanaged C++.
Then
invoke the method in C# by DllImport.

2. Wrap the static lib using managed C++, which will create a dll as .NET
assembly, so C# project can directly use it as reference and call methods
directly.

Not good as C++, if my understanding on approaches is correct, would the
first approach create faster execution for the same function since it is
mostly wrapped by "old faster C++" codes?
Thanks for help

Chris


Jul 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Gaijinco | last post by:
Every now and then and found two ways to resolve a problem. I try to find a way to decide which one is best (at least speed-wise) but I don't know how do I test how long those it take a program to...
3
by: Fluffy Convict | last post by:
I am trying to write a script that changes a textarea wrap realtime, basically like you can switch to and from "wordwrap" in Microsofts Notepad. Because of a bug...
49
by: Neil Zanella | last post by:
Hello, Often I happen to be dealing with nonnegative integers and since I know I won't need negative numbers here I declare them as unsigned simply to make the program somewhat clearer....
10
by: Douglas G | last post by:
I've tried various ideas on this problem, but I don't see word wrapping. Can you point out what is wrong? It's a K&R exercise, and I'm still new to programming. Other pointers would be helpful...
335
by: extrudedaluminiu | last post by:
Hi, Is there any group in the manner of the C++ Boost group that works on the evolution of the C language? Or is there any group that performs an equivalent function? Thanks, -vs
3
by: Jason | last post by:
Anyone know how to make the text wrap in a text box of a DetailsView?
19
by: vamshi | last post by:
Hi all, This is a question about the efficiency of the code. a :- int i; for( i = 0; i < 20; i++ ) printf("%d",i); b:- int i = 10;
9
by: OldBirdman | last post by:
Efficiency I've never stumbled on any discussion of efficiency of various methods of coding, although I have found posts on various forums where individuals were concerned with efficiency. I'm...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.