Galin Iliev's blog

Software Architecture & Development

Top 10 Hidden Gems in SQL Server 2005

Here are ten precious SQL Server 2005 features that could help you make your DB flying:

  1. TableDiff.exe
  2. Triggers for Logon Events (New in Service Pack 2)
  3. Boosting performance with persisted-computed-columns (pcc).
  4. DEFAULT_SCHEMA setting in sys.database_principles
  5. Forced Parameterization
  6. Vardecimal Storage Format
  7. Indexing made easier with SQL Server 2005
  8. Figuring out the most popular queries in seconds
  9. Scalable Shared Databases
  10. Soft-NUMA

Read full article on MS TechNet

TechEd Video - Framework Engineering: Architecting, Designing, and Developing Reusable Libraries

As we know it is very important to write reusable code as this lower the cost of the product and decrease development time. Here is recorded nice presentation of Krzysztof Cwalina on TechEd "Framework Engineering: Architecting, Designing, and Developing Reusable Libraries".

Krzysztof is kind enough to publish slides in XPS format (1.25 MB).

Download video in WMV format (01:07:23 and 371 MB)

image image

Framework Engineering: Architecting, Designing, and Developing Reusable Libraries

This session covers the main aspects of reusable library design: API design, architecture, and general framework engineering processes. Well-designed APIs are critical to the success of reusable libraries, but there are other aspects of framework development that are equally important, yet not widely covered in literature. Organizations creating reusable libraries often struggle with the process of managing dependencies, compatibility, and other design processes so critical to the success of modern frameworks. Come to this session and learn about how Microsoft creates its frameworks. The session is based on experiences from the development of the .NET Framework and Silverlight, and will cover processes Microsoft uses in the development of managed frameworks

WeakReference ?!? Do we have strong one ?!

Have you used WeakReference class? I am sure you, probably, have in connection to GC and Memory Management in .NET (MSDN Magazine Article: Part1 and Part2). Especially if you have written complicated cache mechanisms. ASP.NET cache uses it internally.

It is very convenient because you can have the reference to some object and still allow this object to be collected by Garbage Collector (another description here) or in other words (according MSDN) "Represents a weak reference, which references an object while still allowing that object to be reclaimed by garbage collection."
Here is one example from MSDN Magazine;

   1:  void Method() {
   2:     Object o = new Object();    // Creates a strong reference to the
   3:                                 // object.
   4:   
   5:     // Create a strong reference to a short WeakReference object.
   6:     // The WeakReference object tracks the Object.
   7:     WeakReference wr = new WeakReference(o);
   8:   
   9:     o = null;    // Remove the strong reference to the object
  10:   
  11:     o = wr.Target;
  12:     if (o == null) {
  13:        // A GC occurred and Object was reclaimed.
  14:     } else {
  15:        // a GC did not occur and we can successfully access the Object 
  16:        // using o
  17:     }
  18:  }
  19:   

Here is another example how can be used.

But how does it work? Here is good explanation.

To fully understand how weak references work, let's look inside the managed heap again. The managed heap contains two internal data structures whose sole purpose is to manage weak references: the short weak reference table and the long weak reference table. These two tables simply contain pointers to objects allocated within the managed heap.
Initially, both tables are empty. When you create a WeakReference object, an object is not allocated from the managed heap. Instead, an empty slot in one of the weak reference tables is located; short weak references use the short weak reference table and long weak references use the long weak reference table.
Once an empty slot is found, the value in the slot is set to the address of the object you wish to track—the object's pointer is passed to the WeakReference's constructor. The value returned from the new operator is the address of the slot in the WeakReference table. Obviously, the two weak reference tables are not considered part of an application's roots or the garbage collector would not be able to reclaim the objects pointed to by the tables.

Hope you find it helpful.

P.S. Here are some explanations how can resurrect objects in .NET.