tags:

views:

83

answers:

4

I want to know the in-memory representation of .NET constructs such as "interface", "class", "struct", etc. There's an excellent book for C++ object model - <Inside the C++ Object Model> by Stanley. Lippman, I want a similar book for .NET and C#.

I have read some books about .NET, but they are mostly about the logical usage of .NET. None of them talks about the physical in-memory layout info. I think it's necessary to know at least one implementation of .NET.

I have read about the "Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects" Could someone provide some hints about more in-depth books and articles?

If this info is not publicly avaialble. Shared source one like Mono or Shared Source CLI could be an option.

Many thanks.

A: 

The reason this information is not easily available is almost certainly deliberate on Microsofts behalf.

Microsoft created the .NET Framework and the CLR so you do not have to (unduly) worry yourself about where/how your objects are stored in memory (implmentation details). This "ignorance" is actually one of the biggest benefits of using .NET; you do not need to worry about issues such as manual memory allocation, processor/memory models etc.

The other benefit of this is that it improves security, ie it makes writing malicious code that much harder, although not impossible of course.

CLR Via C# by Jeff Richter is probably the best current book for "under the hood" type .NET information. Chapters 4, 5, 20 and 21 would probably be of most interest regarding layout of .NET types, although, as explained above, you will not find the same level of detail as the C++ object model.

Ash
Thanks Ash. I am doing this for academic purpose, not for development purpose. And SSCLI2.0 is like a maze without a map. A map is necessary.
smwikipedia
As mentioned in the question, Microsoft does publish information of this type. Automatic memory management does not mean you can't (for whatever reason) learn about implementation details. Finally, security through obscurity never works.
Matthew Flaschen
@Matthew, where do I actually say Microsoft does not publish such info? Where also do I say that someone should not learn about .NET implementation details? (I even recommend the ultimate implementation details book for .NET) My point (that you have thoroughly missed) is that in .NET it is simply not necessary to know the in-memory layout of .NET types. Also, I do not refer to "Security through obscurity" at all. I'm talking about the obvious security benefits you get for free in .NET framework, such as bounds checking, safe/unsafe code, safe strings etc.
Ash
+1  A: 

As already mentioned, CLR Via C# is a really good source of information. And if you want to get into the nitty gritty details you can take a look at the SSCLI (Shared Source Common Language Infrastructure), which is a early branch of the initial .NET Framework implementation from the MS source. The current version of SSCLI covers a significant number of framework 2.0 feature set.

http://www.microsoft.com/downloads/details.aspx?FamilyID=8c09fd61-3f26-4555-ae17-3121b4f51d4d

There was also a book that covered the SSCLI, but that was for version 1, but might still be of use.

http://www.amazon.com/Shared-Source-Essentials-David-Stutz/dp/059600351X/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1271220840&amp;sr=8-1

Chris Taylor
A: 

There is another reason that much of this CLI info may be hard to get at - much of it may be implementation details, which could vary between (for example) MS .NET, CF, MF, Silverlight, Mono (regular), Mono (iPhone), etc. And certainly from a language perspective (C# etc) it is well off topic.

You'd have to check the CLI spec (ECMA 335). Either the info is in there (in which case you're sorted) or it isn't (in which case it is an implementation detail).

Marc Gravell
A: 

If you really want to see them, learn about WinDbg and SOS.dll. If you can dive into the live debugging or dump analysis lands, almost nothing is invisible to you.

Regards,

Lex Li