|
-
January 16th, 2006, 04:55 AM
#1
Native code and IL
I haven't had a chance to use managed C++ yet (been working with unmanaged C++ and C#).
If I create a managed C++ project and use a lot of the STL, does the entire project translate into IL or does the unmanaged parts get natively compiled?
I've searched for this answer and I couldn't find anything but it looks like it may translate into IL.
The reason I ask is because I am working on a DLL I want to be usable in C# and VB.Net, however; I would like it natively compiled so I can get the speed boost C++ would give me AND I would like my code to be a little bit more safe. Plus, I enjoy the STL containers more than the Microsoft Collections.
-
January 16th, 2006, 05:24 AM
#2
Re: Native code and IL
In my (brief) trial at creating a managed C++ application I found that the compiler baulked at my use of STL collections in a garbage collected class. There is probably a way round it, but I never had the inclination to find out; and I also prefered STL to the .NET collections. I imagine some others here will enlighten us to the work-around.
-
January 16th, 2006, 09:13 AM
#3
Re: Native code and IL
You can explicity state which file to be unmanaged with the #pragma unmanaged directive. Native stuff remains native, but why not use the dotNet containers instead?
-
January 16th, 2006, 11:12 AM
#4
Re: Native code and IL
 Originally Posted by NoHero
You can explicity state which file to be unmanaged with the #pragma unmanaged directive. Native stuff remains native
But is there no way to use an STL container in a managed class?
, but why not use the dotNet containers instead?
You seem to have to do a lot of casting to get at the contents.
Anyway, I have a lot of source code using STL collections and I wasn't in the mood to go round changing them all.
-
January 16th, 2006, 02:06 PM
#5
Re: Native code and IL
But is there no way to use an STL container in a managed class?
I got something wrong here maybe... Using unmanaged stl in a managed project shouldn't be a problem at all. A managed class can have unmanaged members too, but not vice versa. But remember: Using hardcompiled unmanaged stuff nails your application down the platform it was compiled on.
And yeah the casting is hell, and well it becomes more complicated on the new syntax 
But when creating a new Managed Project I would rather stick on the managed System::Collection classes than on unmanaged STL.
-
January 17th, 2006, 04:32 AM
#6
Re: Native code and IL
 Originally Posted by NoHero
But remember: Using hardcompiled unmanaged stuff nails your application down the platform it was compiled on.
No problem with that here 
BTW What is the syntax for an STL member in a managed class?
Using vector<char> data; caused the compiler to complain about a non-managed member in a garbage collected class.
But when creating a new Managed Project I would rather stick on the managed System::Collection classes than on unmanaged STL.
I suppose if you were starting from scratch that would make sense, though having to do a lot of casting seems like a bit of a backward step.
I'm sure I've heard something about Microsoft adding some sort of templated colections to .NET.
-
January 17th, 2006, 10:41 PM
#7
Re: Native code and IL
 Originally Posted by JohnW@Wessex
I suppose if you were starting from scratch that would make sense, though having to do a lot of casting seems like a bit of a backward step.
I'm sure I've heard something about Microsoft adding some sort of templated colections to .NET.
They added generics, however; they are no where near as powerful as templates and it's a bit awkward to use them.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|