Site Feed

Thursday, March 03, 2005

Deep Copy Objects Using Serialization

Creating duplicates of objects in memory can be complicated. Consider the following code snippet written by Michael Ames.

Copying, Cloning, and Marshalling in .NET

Copying, Cloning, and Marshalling in .NET by Shawn Van Ness -- Even after spending the last few years with the C# language, Shawn Van Ness recently found it worthwhile to step back and analyze what happens in some very simple scenarios, such as copying a value from one variable to another, or passing those variables as arguments to a method call. And that is the focus of this article.

Thursday, November 04, 2004

NET Assembly Structure – Part II

So... let me get back to defining assembly structure, a bit more in detail. The .NET assembly is based on Windows Portable Executable (PE) and Common Object File Format (COFF). This runtime image (.NET assembly) will be generated by .NET specific language compilers and the execution engine (CLR) will be able to load this image and execute.

This extended PE/COFF format facilitate Windows operating system to distinguish runtime images, recognizes Microsoft Intermediate Language (MSIL) or native code, and accommodates metadata as an integral part of the emitted code.

The runtime image includes the following sectors:

Runtime Image File Headers
MS-DOS stub
This stub is used to tell the runtime environment that the module can or cannot be run in MS-DOS mode.
COFF Header
COFF header consists of fields for number identifying target machine (processor type), number of sections, date time stamp the file was created, etc.
PE Header
This would contain standard fields identifying the state of image file, linker versions, code size, etc, Windows OS version specific fields such as OS versions, file checksum, size of stack to reserve, size of heap reserve, and Data directories (for use of OS).
Runtime Header
This header contains all of the runtime-specific data entries and other information such as runtime versions required, location and size of meta data in the image, location of CLR resources, strong name signature, etc, remember the term metadata?

MSIL Code or Native Code

Entry Points
Runtime API’s
The following API’s are exported from mscoree.dll and are used to bootstrap the runtime:
_CorExeMain: This method is called to start execution of an executable program.
_CorDllMain: This method is called for the entry point of a DLL.
Entry Points for Windows CE (if the runtime image is for compact framework)
Shut Down Requirements

Resources
This includes any resources such as image files, or those files associated with globalization.

And that makes up a .net assembly !

The Day That IT Died

At TechEd Amsterdam, acompanied by Don Box on a bass/guitar combination and David Chappell on piano, Pat Helland performed his version of Don McLean's American Pie, reimagined as Mr. CIO Guy.

Video

That is by far the coolest / geekiest / weirdest / bravest / most entertaining thing I have seen in a long, long time!

Awesome.

Steve Ballmer

Steve Ballmer is Chief Executive Officer of Microsoft Corp. Ballmer joined Microsoft in 1980 and was the first business manager hired by Bill Gates. Since then, Ballmer's passion and leadership have become hallmarks of his tenure at the company.

Check out his passion and spirit.



This man is incredible.

Friday, October 29, 2004

.NET Assembly Structure – Part 1

In this blog, I will explain the structure of .net assembly. What is an assembly? Prior to explaining what is an assembly, let me give you all a brief preface on where it begins.

Microsoft, the software giant has gone one step ahead of its competitors to bring out the language independent software development environment. Microsoft has brought out their proprietary .net languages such as C#, VB.NET, C++.net, etc. for diverse skilled developers. These high level languages are in reality an abstraction to an intermediary language, which Microsoft has designed, called MSIL.

The MSIL is structured in such a way that the .NET framework can turn them into native code on any Windows platform using a windows specific execution engine called CLR or Common Language Runtime. Microsoft has compilers written for C#, VB.NET etc. which churns the code into the intermediary language or MSIL.

MSIL, what we can from now on call an assembly, is an executable file when it comes under the hood of .NET runtime. The .NET runtime loads the assembly into a process and does a Just in Time compilation. JIT? This is that feature of the CLR which converts the MSIL into native code. The native code is the instructions which the OS understand and the machine can execute. Here is the catch… we have a Windows specific .NET execution engine. Now if we have .NET execution engine specific to other Operating Systems such as Linux or UNIX, we can then call .NET to be platform independent too. There is definitely an effort in this direction from Open source community. This is called Mono, a .net run time for Linux. Microsoft might have their own justification behind not bringing out runtime for other operating systems, but then, that is another topic for debate.

... to be continued.

Wednesday, October 27, 2004

Garbage Collection

Garbage collection is a mechanism by which the CLR reclaims inaccessible (or unreachable) memory allocated to an object. Question, when does an object become unreachable? This can be determined by the references that an application has to this object at any given point of time. This can happen in different ways. An object can go out of scope or if the reference to an object can be explicitly set to null rendering the references to be invalid. Thus, the Garbage Collector has to keep a track of all objects that needs to be garbage collected.

How does this happen? Let me start by asking to when do the GC first gets invoked? The GC first gets invoked as soon as the first object for the application gets generated on the heap when starting. Once started, the garbage collection process runs on a thread that is separate from the application main thread. This thread is completely inaccessible to the main thread in the application thus providing complete security to the garbage collection thread. Every time an object is allocated a memory space using the new key word, the garbage collection runs.

When the garbage collection runs, it first mark all the objects created in the memory to be garbage collected. Then it looks out for the references that are still alive on the object. It examines the references on an object and if found, it de-marks the object. Then the garbage collector reclaims all memory which was allocated to objects that are no more referenced in the managed code. This process is called mark-and-sweep.