When I rebuild my c++ DLL (which I call from c#) into /CLR (originally native) the performance drops in halfSolution to PInvokeStackImbalance exception (Calling unmanaged C++ dll from C#) - VS2010Native C++ use C# dll via proxy C++ managed dllHow to add a C++ DLL in Windows Phone 8 (C#) FrameworkDebugger does not step into native code when debugging a static lib wrapped in a C++/CLI DLLconversation with typedef variable in c++C# Marshalling to call C++ DLL. COM and threading issueFileNotFoundException when calling remote C# dll from C++/CLRCall DLL C++ functions form C# without block the form controlsconnection sql database in qt in visual studioCalling C++ DLL from C++ and C#
If a person had control of every single cell of their body, would they be able to transform into another creature?
What is the object moving across the ceiling in this stock footage?
Why are C64 games inconsistent with which joystick port they use?
Adding spaces to string based on list
Plot twist where the antagonist wins
Are these reasonable traits for someone with autism?
What does the view outside my ship traveling at light speed look like?
Would Brexit have gone ahead by now if Gina Miller had not forced the Government to involve Parliament?
Why does a perfectly-identical repetition of a drawing command given within an earlier loop 𝘯𝘰𝘵 produce exactly the same line?
How to know if a folder is a symbolic link?
Why is this Simple Puzzle impossible to solve?
Make 24 using exactly three 3s
Should I disclose a colleague's illness (that I should not know) when others badmouth him
Is it unethical to use a published code in my PhD thesis work?
What is the largest (size) solid object ever dropped from an airplane to impact the ground in freefall?
Construct a word ladder
Why does the 6502 have the BIT instruction?
Website returning plaintext password
Why do most published works in medical imaging try to reduce false positives?
Should one buy new hardware after a system compromise?
At what point in European history could a government build a printing press given a basic description?
Why does Mjolnir fall down in Age of Ultron but not in Endgame?
Which is the common name of Mind Flayers?
What is a Centaur Thief's climbing speed?
When I rebuild my c++ DLL (which I call from c#) into /CLR (originally native) the performance drops in half
Solution to PInvokeStackImbalance exception (Calling unmanaged C++ dll from C#) - VS2010Native C++ use C# dll via proxy C++ managed dllHow to add a C++ DLL in Windows Phone 8 (C#) FrameworkDebugger does not step into native code when debugging a static lib wrapped in a C++/CLI DLLconversation with typedef variable in c++C# Marshalling to call C++ DLL. COM and threading issueFileNotFoundException when calling remote C# dll from C++/CLRCall DLL C++ functions form C# without block the form controlsconnection sql database in qt in visual studioCalling C++ DLL from C++ and C#
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
When I changed the DLL build options from native to /CLR, so that I could debug across the c#/c++ boundary, my performance was cut in half.
I developed a native C++ DLL with specific high performance algorithms to solve my computational problems. This DLL I needed to plug into a C# application developed by a business partner and it is used to replace their lower performance algorithm. All was going great, I plugged in my DLL using static wrapper calls, the DLL algorithm was working great showing a 2x performance improvement over original algorithm, but could not debug across boundary.
I then switched the c++ DLL build settings from native to /CLR in order to be able to debug across the c#/c++ DLL boundary and my performance dropped in half.
Cannot figure out why that is the case.
c++ DLL side:
extern "C"
__declspec(dllexport) void* NewCalc()
return (void*)new CalcCL;
__declspec(dllexport) double Calc(void* sCalc, int *Buf, int Cnt)
return ((CalcCl*)sCalc)->Calc(Buf, Cnt);
c# side:
[DllImport("CalcDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int NewCalc();
[DllImport("CalcDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern double Calc(int sCalc, int[] Buf, int Cnt);
...
int sCalc = NewCalc();
...
double res;
int[] MyBuf = new int[1000];
// <Code that fills MyBuf with target data for algorithm>
res = Calc(sCalc, MyBuf, 1000);
c# c++ dll visual-studio-2013
add a comment |
When I changed the DLL build options from native to /CLR, so that I could debug across the c#/c++ boundary, my performance was cut in half.
I developed a native C++ DLL with specific high performance algorithms to solve my computational problems. This DLL I needed to plug into a C# application developed by a business partner and it is used to replace their lower performance algorithm. All was going great, I plugged in my DLL using static wrapper calls, the DLL algorithm was working great showing a 2x performance improvement over original algorithm, but could not debug across boundary.
I then switched the c++ DLL build settings from native to /CLR in order to be able to debug across the c#/c++ DLL boundary and my performance dropped in half.
Cannot figure out why that is the case.
c++ DLL side:
extern "C"
__declspec(dllexport) void* NewCalc()
return (void*)new CalcCL;
__declspec(dllexport) double Calc(void* sCalc, int *Buf, int Cnt)
return ((CalcCl*)sCalc)->Calc(Buf, Cnt);
c# side:
[DllImport("CalcDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int NewCalc();
[DllImport("CalcDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern double Calc(int sCalc, int[] Buf, int Cnt);
...
int sCalc = NewCalc();
...
double res;
int[] MyBuf = new int[1000];
// <Code that fills MyBuf with target data for algorithm>
res = Calc(sCalc, MyBuf, 1000);
c# c++ dll visual-studio-2013
3
Change the debugger type option in the project properties to "mixed" to enable debugging the native code with a C# project. (Or pick both "native" and the appropriate "managed" if attaching to a process.)
– 1201ProgramAlarm
Mar 24 at 5:01
2
Does it matter how well it performs during debugging if you can still get the best performance in production?
– Robert Harvey♦
Mar 24 at 5:06
Also note that code using/clr
will have JIT-time optimizations disabled when debugging, regardless of compiler settings (this can be controlled by a debugger setting -- default is to inhibit optimizations whenever a debugger is attached)
– Ben Voigt
Mar 24 at 5:15
Is it really surprising that very specific optimized C++ code compiled to managed code would be a lot slower? I’m pretty sure Microsoft didn’t spend a lot of time trying to make the compiler produce the best code for these kinds of situations since you’d use native if needed, as you have.
– Sami Kuhmonen
Mar 24 at 5:16
Also note that you're paying both the penalty of reduced optimizations on the C++ side, and slow interop using p/invoke. Normally when using/clr
you writeref class
objects that C# can use directly with no p/invoke.
– Ben Voigt
Mar 24 at 5:17
add a comment |
When I changed the DLL build options from native to /CLR, so that I could debug across the c#/c++ boundary, my performance was cut in half.
I developed a native C++ DLL with specific high performance algorithms to solve my computational problems. This DLL I needed to plug into a C# application developed by a business partner and it is used to replace their lower performance algorithm. All was going great, I plugged in my DLL using static wrapper calls, the DLL algorithm was working great showing a 2x performance improvement over original algorithm, but could not debug across boundary.
I then switched the c++ DLL build settings from native to /CLR in order to be able to debug across the c#/c++ DLL boundary and my performance dropped in half.
Cannot figure out why that is the case.
c++ DLL side:
extern "C"
__declspec(dllexport) void* NewCalc()
return (void*)new CalcCL;
__declspec(dllexport) double Calc(void* sCalc, int *Buf, int Cnt)
return ((CalcCl*)sCalc)->Calc(Buf, Cnt);
c# side:
[DllImport("CalcDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int NewCalc();
[DllImport("CalcDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern double Calc(int sCalc, int[] Buf, int Cnt);
...
int sCalc = NewCalc();
...
double res;
int[] MyBuf = new int[1000];
// <Code that fills MyBuf with target data for algorithm>
res = Calc(sCalc, MyBuf, 1000);
c# c++ dll visual-studio-2013
When I changed the DLL build options from native to /CLR, so that I could debug across the c#/c++ boundary, my performance was cut in half.
I developed a native C++ DLL with specific high performance algorithms to solve my computational problems. This DLL I needed to plug into a C# application developed by a business partner and it is used to replace their lower performance algorithm. All was going great, I plugged in my DLL using static wrapper calls, the DLL algorithm was working great showing a 2x performance improvement over original algorithm, but could not debug across boundary.
I then switched the c++ DLL build settings from native to /CLR in order to be able to debug across the c#/c++ DLL boundary and my performance dropped in half.
Cannot figure out why that is the case.
c++ DLL side:
extern "C"
__declspec(dllexport) void* NewCalc()
return (void*)new CalcCL;
__declspec(dllexport) double Calc(void* sCalc, int *Buf, int Cnt)
return ((CalcCl*)sCalc)->Calc(Buf, Cnt);
c# side:
[DllImport("CalcDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int NewCalc();
[DllImport("CalcDLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern double Calc(int sCalc, int[] Buf, int Cnt);
...
int sCalc = NewCalc();
...
double res;
int[] MyBuf = new int[1000];
// <Code that fills MyBuf with target data for algorithm>
res = Calc(sCalc, MyBuf, 1000);
c# c++ dll visual-studio-2013
c# c++ dll visual-studio-2013
edited Mar 24 at 5:04
Tomasz
asked Mar 24 at 4:55
TomaszTomasz
9217
9217
3
Change the debugger type option in the project properties to "mixed" to enable debugging the native code with a C# project. (Or pick both "native" and the appropriate "managed" if attaching to a process.)
– 1201ProgramAlarm
Mar 24 at 5:01
2
Does it matter how well it performs during debugging if you can still get the best performance in production?
– Robert Harvey♦
Mar 24 at 5:06
Also note that code using/clr
will have JIT-time optimizations disabled when debugging, regardless of compiler settings (this can be controlled by a debugger setting -- default is to inhibit optimizations whenever a debugger is attached)
– Ben Voigt
Mar 24 at 5:15
Is it really surprising that very specific optimized C++ code compiled to managed code would be a lot slower? I’m pretty sure Microsoft didn’t spend a lot of time trying to make the compiler produce the best code for these kinds of situations since you’d use native if needed, as you have.
– Sami Kuhmonen
Mar 24 at 5:16
Also note that you're paying both the penalty of reduced optimizations on the C++ side, and slow interop using p/invoke. Normally when using/clr
you writeref class
objects that C# can use directly with no p/invoke.
– Ben Voigt
Mar 24 at 5:17
add a comment |
3
Change the debugger type option in the project properties to "mixed" to enable debugging the native code with a C# project. (Or pick both "native" and the appropriate "managed" if attaching to a process.)
– 1201ProgramAlarm
Mar 24 at 5:01
2
Does it matter how well it performs during debugging if you can still get the best performance in production?
– Robert Harvey♦
Mar 24 at 5:06
Also note that code using/clr
will have JIT-time optimizations disabled when debugging, regardless of compiler settings (this can be controlled by a debugger setting -- default is to inhibit optimizations whenever a debugger is attached)
– Ben Voigt
Mar 24 at 5:15
Is it really surprising that very specific optimized C++ code compiled to managed code would be a lot slower? I’m pretty sure Microsoft didn’t spend a lot of time trying to make the compiler produce the best code for these kinds of situations since you’d use native if needed, as you have.
– Sami Kuhmonen
Mar 24 at 5:16
Also note that you're paying both the penalty of reduced optimizations on the C++ side, and slow interop using p/invoke. Normally when using/clr
you writeref class
objects that C# can use directly with no p/invoke.
– Ben Voigt
Mar 24 at 5:17
3
3
Change the debugger type option in the project properties to "mixed" to enable debugging the native code with a C# project. (Or pick both "native" and the appropriate "managed" if attaching to a process.)
– 1201ProgramAlarm
Mar 24 at 5:01
Change the debugger type option in the project properties to "mixed" to enable debugging the native code with a C# project. (Or pick both "native" and the appropriate "managed" if attaching to a process.)
– 1201ProgramAlarm
Mar 24 at 5:01
2
2
Does it matter how well it performs during debugging if you can still get the best performance in production?
– Robert Harvey♦
Mar 24 at 5:06
Does it matter how well it performs during debugging if you can still get the best performance in production?
– Robert Harvey♦
Mar 24 at 5:06
Also note that code using
/clr
will have JIT-time optimizations disabled when debugging, regardless of compiler settings (this can be controlled by a debugger setting -- default is to inhibit optimizations whenever a debugger is attached)– Ben Voigt
Mar 24 at 5:15
Also note that code using
/clr
will have JIT-time optimizations disabled when debugging, regardless of compiler settings (this can be controlled by a debugger setting -- default is to inhibit optimizations whenever a debugger is attached)– Ben Voigt
Mar 24 at 5:15
Is it really surprising that very specific optimized C++ code compiled to managed code would be a lot slower? I’m pretty sure Microsoft didn’t spend a lot of time trying to make the compiler produce the best code for these kinds of situations since you’d use native if needed, as you have.
– Sami Kuhmonen
Mar 24 at 5:16
Is it really surprising that very specific optimized C++ code compiled to managed code would be a lot slower? I’m pretty sure Microsoft didn’t spend a lot of time trying to make the compiler produce the best code for these kinds of situations since you’d use native if needed, as you have.
– Sami Kuhmonen
Mar 24 at 5:16
Also note that you're paying both the penalty of reduced optimizations on the C++ side, and slow interop using p/invoke. Normally when using
/clr
you write ref class
objects that C# can use directly with no p/invoke.– Ben Voigt
Mar 24 at 5:17
Also note that you're paying both the penalty of reduced optimizations on the C++ side, and slow interop using p/invoke. Normally when using
/clr
you write ref class
objects that C# can use directly with no p/invoke.– Ben Voigt
Mar 24 at 5:17
add a comment |
1 Answer
1
active
oldest
votes
With the given interface there is no benefit to compiling with /clr at all. Make the native C++ code debuggable by right-clicking your main C# project > Properties > Debug tab > tick the "Enable native code debugging" checkbox. That enables both the managed and unmanaged debugging engines. You cannot single-step into the native code, a breakpoint on the Calc() function is required to effect a debug engine change. You might still favor a unit test written in native C++ if setting breakpoints is awkward.
The other thing you need to take care of is that you're building the C++ code with Debug settings enabled. You got that now, that's why the code seems to be half as slow. Only do a perf test with Release build settings so you're sure that the optimizer is enabled. Best thing to do is to include the native C++ project in the C# solution so you always build the right flavor. And you have to make sure that the correct DLL gets copied into the C# main project's build directory, usually done with a post-build event. That copy step must be different for the Debug and Release configurations.
Note that the [DllImport] declarations are not correct. The return type of NewCalc() must be IntPtr so it also works in 64-bit code. Perf-testing the 64-bit build of the C++ code is something else you want to try, it can boost perf if the Calc() function uses floating point math. Actually using /clr can be useful to make the interface better, you'll however have to learn how to write C++/CLI code and avoid building the native C++ code with /clr.
1
Not onlyNewCalc
also in theCalc
function thesCalc
parameter should beIntPtr
.
– ckuri
Mar 24 at 7:45
Of course, the C# compiler reminds him about that.
– Hans Passant
Mar 24 at 7:47
Thank you this answer was very helpful and addressed my needs for debugging of the native DLL. Also good catch on the IntPtr.
– Tomasz
Mar 25 at 13:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320847%2fwhen-i-rebuild-my-c-dll-which-i-call-from-c-into-clr-originally-native-t%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
With the given interface there is no benefit to compiling with /clr at all. Make the native C++ code debuggable by right-clicking your main C# project > Properties > Debug tab > tick the "Enable native code debugging" checkbox. That enables both the managed and unmanaged debugging engines. You cannot single-step into the native code, a breakpoint on the Calc() function is required to effect a debug engine change. You might still favor a unit test written in native C++ if setting breakpoints is awkward.
The other thing you need to take care of is that you're building the C++ code with Debug settings enabled. You got that now, that's why the code seems to be half as slow. Only do a perf test with Release build settings so you're sure that the optimizer is enabled. Best thing to do is to include the native C++ project in the C# solution so you always build the right flavor. And you have to make sure that the correct DLL gets copied into the C# main project's build directory, usually done with a post-build event. That copy step must be different for the Debug and Release configurations.
Note that the [DllImport] declarations are not correct. The return type of NewCalc() must be IntPtr so it also works in 64-bit code. Perf-testing the 64-bit build of the C++ code is something else you want to try, it can boost perf if the Calc() function uses floating point math. Actually using /clr can be useful to make the interface better, you'll however have to learn how to write C++/CLI code and avoid building the native C++ code with /clr.
1
Not onlyNewCalc
also in theCalc
function thesCalc
parameter should beIntPtr
.
– ckuri
Mar 24 at 7:45
Of course, the C# compiler reminds him about that.
– Hans Passant
Mar 24 at 7:47
Thank you this answer was very helpful and addressed my needs for debugging of the native DLL. Also good catch on the IntPtr.
– Tomasz
Mar 25 at 13:19
add a comment |
With the given interface there is no benefit to compiling with /clr at all. Make the native C++ code debuggable by right-clicking your main C# project > Properties > Debug tab > tick the "Enable native code debugging" checkbox. That enables both the managed and unmanaged debugging engines. You cannot single-step into the native code, a breakpoint on the Calc() function is required to effect a debug engine change. You might still favor a unit test written in native C++ if setting breakpoints is awkward.
The other thing you need to take care of is that you're building the C++ code with Debug settings enabled. You got that now, that's why the code seems to be half as slow. Only do a perf test with Release build settings so you're sure that the optimizer is enabled. Best thing to do is to include the native C++ project in the C# solution so you always build the right flavor. And you have to make sure that the correct DLL gets copied into the C# main project's build directory, usually done with a post-build event. That copy step must be different for the Debug and Release configurations.
Note that the [DllImport] declarations are not correct. The return type of NewCalc() must be IntPtr so it also works in 64-bit code. Perf-testing the 64-bit build of the C++ code is something else you want to try, it can boost perf if the Calc() function uses floating point math. Actually using /clr can be useful to make the interface better, you'll however have to learn how to write C++/CLI code and avoid building the native C++ code with /clr.
1
Not onlyNewCalc
also in theCalc
function thesCalc
parameter should beIntPtr
.
– ckuri
Mar 24 at 7:45
Of course, the C# compiler reminds him about that.
– Hans Passant
Mar 24 at 7:47
Thank you this answer was very helpful and addressed my needs for debugging of the native DLL. Also good catch on the IntPtr.
– Tomasz
Mar 25 at 13:19
add a comment |
With the given interface there is no benefit to compiling with /clr at all. Make the native C++ code debuggable by right-clicking your main C# project > Properties > Debug tab > tick the "Enable native code debugging" checkbox. That enables both the managed and unmanaged debugging engines. You cannot single-step into the native code, a breakpoint on the Calc() function is required to effect a debug engine change. You might still favor a unit test written in native C++ if setting breakpoints is awkward.
The other thing you need to take care of is that you're building the C++ code with Debug settings enabled. You got that now, that's why the code seems to be half as slow. Only do a perf test with Release build settings so you're sure that the optimizer is enabled. Best thing to do is to include the native C++ project in the C# solution so you always build the right flavor. And you have to make sure that the correct DLL gets copied into the C# main project's build directory, usually done with a post-build event. That copy step must be different for the Debug and Release configurations.
Note that the [DllImport] declarations are not correct. The return type of NewCalc() must be IntPtr so it also works in 64-bit code. Perf-testing the 64-bit build of the C++ code is something else you want to try, it can boost perf if the Calc() function uses floating point math. Actually using /clr can be useful to make the interface better, you'll however have to learn how to write C++/CLI code and avoid building the native C++ code with /clr.
With the given interface there is no benefit to compiling with /clr at all. Make the native C++ code debuggable by right-clicking your main C# project > Properties > Debug tab > tick the "Enable native code debugging" checkbox. That enables both the managed and unmanaged debugging engines. You cannot single-step into the native code, a breakpoint on the Calc() function is required to effect a debug engine change. You might still favor a unit test written in native C++ if setting breakpoints is awkward.
The other thing you need to take care of is that you're building the C++ code with Debug settings enabled. You got that now, that's why the code seems to be half as slow. Only do a perf test with Release build settings so you're sure that the optimizer is enabled. Best thing to do is to include the native C++ project in the C# solution so you always build the right flavor. And you have to make sure that the correct DLL gets copied into the C# main project's build directory, usually done with a post-build event. That copy step must be different for the Debug and Release configurations.
Note that the [DllImport] declarations are not correct. The return type of NewCalc() must be IntPtr so it also works in 64-bit code. Perf-testing the 64-bit build of the C++ code is something else you want to try, it can boost perf if the Calc() function uses floating point math. Actually using /clr can be useful to make the interface better, you'll however have to learn how to write C++/CLI code and avoid building the native C++ code with /clr.
answered Mar 24 at 7:33
Hans PassantHans Passant
802k11013482141
802k11013482141
1
Not onlyNewCalc
also in theCalc
function thesCalc
parameter should beIntPtr
.
– ckuri
Mar 24 at 7:45
Of course, the C# compiler reminds him about that.
– Hans Passant
Mar 24 at 7:47
Thank you this answer was very helpful and addressed my needs for debugging of the native DLL. Also good catch on the IntPtr.
– Tomasz
Mar 25 at 13:19
add a comment |
1
Not onlyNewCalc
also in theCalc
function thesCalc
parameter should beIntPtr
.
– ckuri
Mar 24 at 7:45
Of course, the C# compiler reminds him about that.
– Hans Passant
Mar 24 at 7:47
Thank you this answer was very helpful and addressed my needs for debugging of the native DLL. Also good catch on the IntPtr.
– Tomasz
Mar 25 at 13:19
1
1
Not only
NewCalc
also in the Calc
function the sCalc
parameter should be IntPtr
.– ckuri
Mar 24 at 7:45
Not only
NewCalc
also in the Calc
function the sCalc
parameter should be IntPtr
.– ckuri
Mar 24 at 7:45
Of course, the C# compiler reminds him about that.
– Hans Passant
Mar 24 at 7:47
Of course, the C# compiler reminds him about that.
– Hans Passant
Mar 24 at 7:47
Thank you this answer was very helpful and addressed my needs for debugging of the native DLL. Also good catch on the IntPtr.
– Tomasz
Mar 25 at 13:19
Thank you this answer was very helpful and addressed my needs for debugging of the native DLL. Also good catch on the IntPtr.
– Tomasz
Mar 25 at 13:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320847%2fwhen-i-rebuild-my-c-dll-which-i-call-from-c-into-clr-originally-native-t%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Change the debugger type option in the project properties to "mixed" to enable debugging the native code with a C# project. (Or pick both "native" and the appropriate "managed" if attaching to a process.)
– 1201ProgramAlarm
Mar 24 at 5:01
2
Does it matter how well it performs during debugging if you can still get the best performance in production?
– Robert Harvey♦
Mar 24 at 5:06
Also note that code using
/clr
will have JIT-time optimizations disabled when debugging, regardless of compiler settings (this can be controlled by a debugger setting -- default is to inhibit optimizations whenever a debugger is attached)– Ben Voigt
Mar 24 at 5:15
Is it really surprising that very specific optimized C++ code compiled to managed code would be a lot slower? I’m pretty sure Microsoft didn’t spend a lot of time trying to make the compiler produce the best code for these kinds of situations since you’d use native if needed, as you have.
– Sami Kuhmonen
Mar 24 at 5:16
Also note that you're paying both the penalty of reduced optimizations on the C++ side, and slow interop using p/invoke. Normally when using
/clr
you writeref class
objects that C# can use directly with no p/invoke.– Ben Voigt
Mar 24 at 5:17