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 / CLR / September 2003

Tip: Looking for answers? Try searching our database.

Object Instantiation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hanuman - 07 Jul 2003 14:19 GMT
I'm trying to understand the details of calling "New" on a
managed object.

In the COM world, calling "New" caused the following
superset of events:
1.  The SCM resolves the path to the class in the registry
by using its CLSID.
2.  The object's class factory creates its instance in
memory, and the instance's pointer is returned to the
client by the SCM.
3.  The client calls the IUnKnown AddRef() method on the
object to increment its internal reference count.

As far as I've been able to determine, the following
events occur when you call "New" on a managed object:
1.  The .Net runtime looks for the requested assembly by
querying the GAC first, then any CodeBase entries in
the .config file, and finally by probing.
2.  The Garbage Collector allocates space in the managed
heap for an instance of the object.
3.  The runtime creates an instance of the object

Questions:
1.  Am I missing any steps?
2.  COM objects provide class factories for instantiation.
How does the .Net runtime create object instances?  

Thank you for your input!
Simon Hall [MSFT] - 07 Jul 2003 23:18 GMT
Hello,

The following document should describe how assemblies are located:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconassemblies.asp. This should provide you with information as to how
types are resolved.

As for object instantiation, assemblies contain enough information (or
metadata) to fully describe their layout. As a result, the runtime is fully
responsible for allocating and initializing type instantiations based on
type resolution and constructor signatures.

Because of the runtime's garbage collection mechanism, AddRef and Release
are no longer necessary in managed code (barring COM interop, of course).

Cheers,
Simon

--------------------
>Content-Class: urn:content-classes:message
>From: "Hanuman" <dhaeseler@ozcap.com>
[quoted text clipped - 44 lines]
>
>Thank you for your input!

Signature

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note:  For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Hanuman - 07 Jul 2003 23:27 GMT
Thank you!

>-----Original Message-----
>Hello,
[quoted text clipped - 64 lines]
>>
>>Thank you for your input!
Calvin - 08 Jul 2003 19:58 GMT
>As for object instantiation, assemblies contain enough information (or
>metadata) to fully describe their layout. As a result, the runtime is fully
>responsible for allocating and initializing type instantiations based on
>type resolution and constructor signatures.

But I've seen something different when you try to
instantiate an object derived from ContextBoundObject.

I used debug to monitor the process. When you call new a
ContextBoundObject

===============
Class A : ContextBoundObject
{
}

A a = new A();
===============
You won't get an object of type A, you will get
__TransparentProxy instead.

a.GetType() is not available at the watch window, but in
local variable window, you will see it's type of
__TransparentProxy.

But if you say:

Type T = a.GetType(); in your code, use your debugger, you
will see T is typeof(A).

It's just weird, I am not sure how the runtime process the
ContextBoundObject.

Calvin
Simon Hall [MSFT] - 30 Sep 2003 01:49 GMT
Calvin,

__TransparentProxy is an internal CLR type used for context bound and
remoted objects. This type often wraps the true type. The debugger only
exposes types and fields, which means that it is not smart enough to unwrap
the object to show you the true type. For a *much* more detailed
explanation of these internal types, please see Chris Brumme's blog entry
on this subject:

http://blogs.gotdotnet.com/cbrumme/PermaLink.aspx/24e9e5f5-9923-4cf9-b097-9c
018c69d5cb

Cheers,
Simon

--------------------
>Content-Class: urn:content-classes:message
>From: "Calvin" <szguoxz@hotmail.com>
>Sender: "Calvin" <szguoxz@hotmail.com>
>References: <0a1a01c3448a$7477a6c0$a101280a@phx.gbl>
<u6uG$WNRDHA.2012@cpmsftngxa09.phx.gbl>
>Subject: RE: Object Instantiation
>Date: Tue, 8 Jul 2003 11:58:22 -0700
[quoted text clipped - 50 lines]
>
>Calvin

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.