473,769 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keeping a handle on your transitions in a mixed assembly

Our project consists of some mixed .dlls and recently we noticed that it had slowed down. When I
investigated I figured out that some inlineable methods of a native C++ type were compiled into (not
inlined) IL methods. Thus we ended up with the standard two entry points with the native one
thunking over to the managed one for native callers.

The thing is, 99.9% of the call-sites to these inlineable methods on this native type are from
native code. Exactly 1 callsite to just a couple of them are from IL. The actual compiland for
the native type is in fact not even in the affected .dll; rather it is in another .dll that contains
no managed call sites to the methods in question at all. The affected .dll contain modules that
include the header for the native C++ type that contains the inlineable method bodies. I guess when
the compiler decides not to inline a method (for whatever reason) you end up with a copy of the
not-inlined method in each .dll that uses it. Makes sense. That way you don't have to dllexport
your inlineable methods.

I surmise that my problem is caused by the single /clr compiland linked into the affected .dll that
includes the header file for the native type and calls a couple of the inlineable methods. I
imagine that I can eliminate the problem by making sure that in the source for that compiland the
header in question is included as follows:

#pragma unmanaged
#include <MyPerformanceS ensitiveNativeT ype.h>
#pragma managed

But this seems quite fragile. This and other headers for native types are going to be getting
#included in /clr compiled compilands by programmers who are not going to know to carefully take
this measure. I need some way to try to enforce it. Ideally I'd get a build-time error the instant
someone did something that would have my native type's inlineable methods getting compiled into IL.
It's not what I want. I want to penalize the managed callers and make them go to native code - not
penalize native callers and make them go to managed code. After all, these are native types with
99% native callers. I don't see a good way to do it. I wish the compiler would automatically
#define/#undef some macro depending upon whether it was in an #pragma managed or #pragma unmanaged
section. Then I could put something like this at the top of my perf sensitive native C++ headers
that contain inlineable methods:

#if defined (CODEGEN_IS_IL)
#error You should not include this header in a pragma managed section.
#endif

It would be even better if I could push the current state, set the current state to unmanaged, and
then pop the original state at the end of the header file. I'm afraid that withtout something to
help me police this it will be quite difficult to keep undesirable transitions from cropping up over
and over as many different programmers work on the project.

Bern McCarty
Bentley Systems, Inc.
Nov 17 '05 #1
1 999
Hi Bern,
I wish the compiler would automatically #define/#undef some macro dependingupon whether it was in an #pragma managed or #pragma unmanaged
section. Then I could put something like this at the top of my perf sensitivenative C++ headers that contain inlineable methods:
...


Do you mean you would like the compiler could automatically define some
macro which depends on whether the code was in an #pragma managed or
#pragma unmanaged section, if so, I suggest can submit a product feedback
at:

http://register.microsoft.com/mswish...=EN-US&gssnb=1
Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default...sdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 17 '05 #2

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

Similar topics

3
1797
by: Nadav | last post by:
Hi, I am writing a mixed mode application, I have a mixed mode Assembly manipulating a managed byte array, to access this array in unmanaged code I '__pin' the array, As I understand, pining an object guarantee that it will not be collected by the GC ( by increasing it's refcount or so ), Taking that in mind, looking at the code generated by the compiler I can't see anything taking care of the GC refcount... following is the pinned variable...
8
4525
by: Ted Miller | last post by:
Hi folks, I'm looking at moving a large base of C++ code to .Net under tight time constraints. The code runs in mission-critical environments, and I am extremely concerned about the loader lock problem and the potential for deadlocks. After pouring over the available information, and trying a few experiments, I am still left with a few questions and issues I hope someone out there can shed some light on.
8
3514
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
8
1999
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid the usage of old style COM, my alternative is to expose my unmanaged interface through the CLI, to achieve that I have created a mixed mode DLL in which my unmanaged class are defined. When referencing the DLL just described in another mixed mode EXE...
7
1433
by: Kevin Frey | last post by:
Using .NET 1.1. We have a mixed-mode assembly written in Managed C++ that we are using from an ASP.NET application that has been coded using C#. The mixed-mode assembly has its own "initialisation" routine to cater for any potential "mixed-mode DLL loading problem". Some of our code uses thread-local-storage, and in the DllMain for my mixed-mode assembly I did the appropriate initialisation of the thread-local-storage object on...
8
2321
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR types. The problem: I have a number of mixed-mode functions which I want reuse. These functions revolve around converting a CLR String to a C++ std::string or
0
1295
by: MC-Advantica | last post by:
I have built a managed wrapper class and assembly that expose much functionality available in unmanaged legacy DLLs. I can write VB apps that interface with the managed assembly, and the managed assembly makes calls to the legacy dlls. All seems to work fine when the assembly is a private assembly. When I go through the process of strong naming the assembly and placing it into the GAC, none of my VB apps will initialize. I have gone to...
0
1226
by: MC-Advantica | last post by:
I have built a managed wrapper class and assembly that expose much functionality available in unmanaged legacy DLLs. I can write VB apps that interface with the managed assembly, and the managed assembly makes calls to the legacy dlls. All seems to work fine when the assembly is a private assembly. When I go through the process of strong naming the assembly and placing it into the GAC, none of my VB apps will initialize. I have gone to...
7
4807
by: =?Utf-8?B?SmltIFdhbHNo?= | last post by:
I'm new to working with mixed assemblies. All of my previous experience has been with VC++/MFC in native, unmanaged applications. When I create a mixed assembly in which one or more of the files compiles with /clr the instructions say that I need to change the switch for Debug information format from Program Database for Edit & Continue to disabled. At runtime I find that I am not able to set breakpoints in the managed code, nor trace...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9860
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.