Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2005

Tip: Looking for answers? Try searching our database.

Cost of reflection vs. ref ptrs

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ole Nielsby - 15 Nov 2005 02:54 GMT
I need to interface an interpreted non-.NET language with the CLR
classes (v. 2.0), for writing winform apps and VS add-ins. The language
uses names rather than position or type to distinguish parameters.

The .NET framework classes and objects will be exposed through
unmanaged C++ wrappers that hold  ref  pointers. Calls will go
through .NET reflection objects, searching the methods of the
type of the object for one with matching method name and parameter
names.

For this to perform reasonably, the C++ wrappers will need to extract
method information using .NET reflection, and keep it around between
calls.

My question is: what should be kept by the wrappers? .NET reflection
objects or method indexes?

If I keep the reflection objects, there will be a substantial amount
of managed references in unmanaged C++ objects - how will this
affect memory management and GC performance?

OTOH if I stay slim and keep method indexes, each interop call will
involve more reflection calls. Will these be expensive?

Thx/Ole Nielsby
Mattias Sjögren - 17 Nov 2005 21:24 GMT
Ole,

>My question is: what should be kept by the wrappers? .NET reflection
>objects or method indexes?

What are these method indexes? Is it the index into the array returned
by Type.GetMethods for a certain method name?

Since you're targeting v2.0 you could consider storing method tokens
instead (see MemberInfo.MetadataToken and Module.ResolveMethod()).

>If I keep the reflection objects, there will be a substantial amount
>of managed references in unmanaged C++ objects - how will this
>affect memory management and GC performance?

Well it will prevent the MethodInfo objects to be garbage collected
which may be a bad thing.

If you haven't already I recommend reading
http://msdn.microsoft.com/msdnmag/issues/05/07/Reflection/default.aspx

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Ole Nielsby - 17 Nov 2005 22:24 GMT
> Ole,
>
>>My question is: what should be kept by the wrappers? .NET reflection
>>objects or method indexes?

> Since you're targeting v2.0 you could consider storing method tokens
> instead (see MemberInfo.MetadataToken and Module.ResolveMethod()).

Seems a good idea, thanks. I hadn't noticed these.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.