Wintellect  

Many readers have asked me if an electronic version of my book is available. Unfortunately, the answer is no and there are no plans to make one available. Some older versions of my book were available in electronic form but Microsoft Press and I discovered that many people took the file and posted it on the web. Some people even sold the files which they clearly had to right to do. So, we decided to stop offerring my books in electronic form. It is sad that a few bad apples spoil the bunch.

Some (potential) readers have asked me to post the complete table of contents for my new Windows via C/C++ book. Here it is:

Part I Required Reading
 1 Error Handling
 2 Working with Characters and Strings
 3 Kernel Objects

Part II Getting Work Done
 4 Processes
 5 Jobs
 6 Thread Basics
 7 Thread Scheduling, Priorities, and Affinities
 8 Thread Synchronization in User Mode
 9 Thread Synchronization with Kernel Objects
 10 Synchronous and Asynchronous Device I/O
 11 The Windows Thread Pool
 12 Fibers

Part III Memory Management
 13 Windows Memory Architecture
 14 Exploring Virtual Memory
 15 Using Virtual Memory in Your Own Applications
 16 A Thread’s Stack
 17 Memory-Mapped Files
 18 Heaps

Part IV Dynamic-Link Libraries
 19 DLL Basics
 20 DLL Advanced Techniques
 21 Thread-Local Storage
 22 DLL Injection and API Hooking

Part V Structured Exception Handling
 23 Termination Handlers
 24 Exception Handlers and Software Exceptions
 25 Unhandled Exceptions, Vectored Exception Handling, and C++ Exceptions
 26 Error Reporting and Application Recovery

Part VI Appendixes
 A The Build Environment
 B Message Crackers, Child Control Macros, and API Macros

I get a lot of e-mails asking me if I will be updating my CLR via C# book for .NET 3.5. This blog entry will asnwer this question.

Here is the short answer: NO, I am not updating the book.

Here is the long answer: My CLR via C# book was last updated for .NET 2.0 and I have no intention of updating the book for .NET 3.0 or .NET 3.5. The reason is because my book is really about the CLR and .NET 3.0 and 3.5 still run on top of CLR 2.0.

.NET 3.0 and 3.5 is really CLR 2.0 plus some new DLLs that contain new class libraries for WPF, WCF, WF, Addin support and Linq support. My book has never covered any ancillary class libraries; it has always focused on the CLR itself and the small subset of class library types that talk directly to the runtime engine. 

In addition, .NET 3.0 shipped with C# 2.0 and so no changes were made to the C# language/compiler either. Of course, .NET 3.5 does ship with C# 3.0 which does offer many new features (automatically-implemented properties, implicitly typed local variables, extension methods, lambda expressions, object initializers, anonymous types, implicitly typed arrays, partial methods, query expressions, and expression tress). However, all of these features are just compiler syntactic sugar to make syntax easier for programmers. Many of these features are very simple to understand and grasp so I feel that it is not worth updating my book just to cover the new syntax offered by C# to accomplish things you already could do.

 

While many of the C# 3.0 features are needed to fully leverage the various set of LINQ technologies (Linq to Object, Linq to XML, Linq to Sql, Linq to DataSet, and Linq to Entities). And, while I will address the new C# language features in some future edition of my book (to coincide with the release of a new CLR version), I will never cover LINQ itself; just the architecture that makes LINQ possible.

Also, I just recently completed updating my Windows book (Windows via C/C++, 5th Edition, Microsoft Press) for Windows Vista and Windows Server 2008. 

First, the bad news: A while ago, Microsoft Press and I bantered around the idea of producing a version of my "CLR via C#" book targeted towards C++/CLI users. The book was going to be titled "CLR via C++/CLI" (catchy title, eh?). As I am not a C++/CLI expert,we thought we'd find another author for me to work with to produce the book. Unfortunatel, we were unable to find an author and this book project is officially dead.

Now, the good news: My last Win32 book came out around 2000. Several years ago, Microsoft Press declared the book out-of-print which made it near impossible for anyone to fnd. Well, I am revising the book wih a co-author. The book will be updated for Windows Vista/Server 2008 and the book should be out by the end of 2007. The tentative title is "Windows via C++, 5th Edition"

Well, I'm very pleased to announce that the "Windows SideShow .NET Framework Components 1.0 (Beta)" is avialable as of today (January 18, 2007).

You can download it from here: http://www.microsoft.com/downloads/details.aspx?FamilyId=06FA2ACE-A42D-4117-821C-BCE80786F1C4&displaylang=en

This is the managed API that I personally implemented for Microsoft to make it easy for managed developers to write SideShow gadget applications for Windows Vista.

I wrote about SideShow and this API in the January 2007 issue of MSDN Magazine. The article can be found here: http://msdn.microsoft.com/msdnmag/issues/07/01/SideShow/default.aspx

My API is being used to help produce Media Center remote controls such as these:

http://www.cepro.com/products/press/16727.html

http://www.engadget.com/2006/12/21/ricavisions-vista-mce-sideshow-remote-does-bluetooth-at-100-met/

http://www.engadget.com/2007/01/09/hands-on-with-a-bunch-of-sideshow-remotes/

 

Hi all,

I have been silent on the blog as usual but thought I'd add an entry today bring you up-to-date on my activities.

I have been extremely busy. Wintellect has gotten some big deals lately which has had me travelling and teaching my .NET Framework class and my new Building Responsive, Reliable, and Scalable Applications and Components class (AKA my Threading class).

In between all this work, I have been reseaching new Windows Vista features that affect threading such as I/O cancellation, wait chain traversal, logical processor information, I/O priorities, transactional file system and registry, and more. In fact, I've added support for a lot of this stuff in my Power Threading library already so that managed developers can use a lot of this stuff when running on Vista. I also plan to write about this stuff in an upcoming Concurrent Affairs column in MSDN Magazine.

Also, Windows Vista has a new feature called SideShow and Microsoft contracted me to produce the managed interface to this new feature. After Vista ships, Microsoft will make the Microsoft.SideShow.dll (which was created by me) available either via Windows Update and/or in the Vista SDK. I explain how to use this new Vista feature and my library in an upcoming MSDN Magazine article (I think the article comes out in the January 2007 issue).

I really like the new SideShow feature and expect to be doing more work with Microsoft to help bring this feature more into mainstream usage.

The Power Collections Library on http://Wintellect.com no longer requires that you register with Wintellect.

As of yesterday, you can simply download the file and start using the Power Collections immediately.

 

Well, it has been a long since I last blogged and I've been incredibly busy the past year. I thought I'd share with you some of the things I've done and some of the things I'll be doing.

First, my new book is finished and should be shipping to customers within a week or so. I just got 2 advanced copies of it earlier this week. I think this is my best book ever and I'm incredibly proud of it. This book is the 2nd edition of my “Applied Microsoft .NET Framework Programming” book. I changed the title to “CLR via C#” as the book really focuses on the CLR from the perspective of the C# programmer. You can find it here: http://www.amazon.com/gp/product/0735621632/sr=8-1/qid=1140158045/ref=pd_bbs_1/104-9334151-2570318?%5Fencoding=UTF8http://www.amazon.com/gp/product/0735621632/sr=8-1/qid=1140158045/ref=pd_bbs_1/104-9334151-2570318?%5Fencoding=UTF8. This edition is pretty much a re-write from the first edition. I added a lot of content related to best practices, design guidelines, and versioning. And, of course, there is coverage of new CLR/C# 2.0 features such as generics, anonymous methods, friend assemblies, nullable types, etc. I also added 2 new chapters on asynchronous programming and thread synchronization.

There is a chance that we will produce a “CLR via C++/CLI” version of the book; I'll know for sure in a few months. There will not be a VB version of the book as it has not proven to be cost effective. The source code for all the book’s code samples will be available on the Wintellect web site in mid- to late-March.

Second, I have been busy doing a lot of thread-related work. I am producing a course tentatively entitled “Effective use of .NET Threading in a Multi-Core Processor World.” I have noticed a big increase in developers focusing on how to take advantage of multi-core CPUs. In fact, this is why I now write the Concurrent Affairs column for MSDN magazine. Threading, synchronization, asynchronous operations, reliability, application responsiveness, and scalability have always been pet interests of mine for many years – my Win32 books had 5 chapters on the subject and I added 2 chapters on the subject to my new .NET book. I just love this stuff. I first start teaching this course at Microsoft in early March. If you’re interested in having me teach this course to you and your company, please contact our sales department.

 

Third, I like threading so much that I’ve started doing some contract work at Microsoft on a project of theirs called the Concurrency and Coordination Runtime (CCR). I’ll be writing about this soon in my MSDN Concurrent Affairs column. Until then, you can get a sneak preview of it by looking at a channel 9 video: http://channel9.msdn.com/Showpost.aspx?postid=143582. This video will give a sense of it but don’t get too into the syntax yet because we’re changing the programming model significantly right now.

 

Fourth, I have been polishing up my .NET Power Threading library. This library has many useful classes in it for people who want to start taking advantage of threading stuff. The library has many thread synchronization locks (and diagnostic classes) that I wrote myself that have incredibly high performance. There is also my own thread pool and a set of asynchronous programming model classes that perform significantly faster than the CLR’s BeginInvoke stuff. Working on my course had caused me to really polish things up to the point where the code is commercial quality. I will be offering the library on the Wintellect web site some time in mid- to late-March. The library will be royalty free – please see the EULA that comes with the library for some minor restrictions on its use.

 

Fifth, I have also been playing around a lot with C# 3.0 features and will be doing the Devscovery keynote on C# 3.0. If you’d like to see it, please register at http://Devscovery.com/. I’ll also be presenting a bunch of talks on threading and reliability.

 

Sixth, I’ve also been spending a good bit of time on Windows Communication Foundation stuff. I’ve been reviewing and contributing a bit to our resident Indigo expert, Justin Smith, as he produces our Indigo course and he is also writing a book on Indigo to be published by Microsoft Press.

 

Seventh, I’ve also been spending a lot of time playing with Windows Vista. I run it in a VPC right now but I expect to install it and use it daily once beta 2 becomes available.

 

Anyway, there seems to be no shortage of technology-related things to play with and keep me busy. Now that the book project is done, I can really dive into this stuff and have some fun.

 

On the non-technical front, my wife and I want to go on a well-deserved and long-delayed vacation. We’ll probably go to Sedona, AZ for sun and warmth – Seattle hasn’t had great weather the past few months and it’s starting to get to me. We’re also planning a long weekend trip to Whistler Mountain in Canada in a few weeks. I also look forward to spending some real quality time with my 3 year old son, Aidan. Aidan wrote the forward of my new book – you should check it out – he is very insightful for a 3 year old. There is a picture of he and I in the book too.

A reader of my books asked me some .NET Questions regarding JIT compiler/strong-naming security. I thought I'd share his questions and my answers with you:

1.    According to Microsoft documentation the Just In-Time Compiler takes the following attributes of the machine into account when producing the executable code.  Define how these factors alter the output.  For example what is meant by CPU Type, what changes to the OS will affect the output.

·         The version of the .NET Framework.

[JeffRichter] There may be bugs in the JIT that get fixed in a future release or the CLR may add some features that require that the code be produced differently. For example, in Whidbey, the JIT changes has a different way of calling interface methods than it had in Everett because some internal data structures changed.

 

·         The CPU type (family).

[JeffRichter] The JIT compiler emits code depending on the type of CPU that is in the computer. Obviously code JITted for an x86 CPU will not run on an Itanium (IA64) CPU. But, the JITter can even produce different code for a Pentium 4 versus a Pentium 5.

 

·         The version of the operating system.

[JeffRichter] The JITter may embed the address of some Win32 APIs in to the native code produced. The address of these APIs could change between different service packs of Windows XP (for example)

 

·         The exact identity of the assembly (recompilation changes identity).

[JeffRichter] Obviously, if the assembly changes, the code must be re-compiled.

 

·         The exact identity of all assemblies that the assembly references (recompilation changes identity).

[JeffRichter] The JIT can inline methods contained in one assembly when JIT-compiling a method in another assembly. If the referenced assembly changes, then this may have changed as well and the JITter needs to re-JIT using the new IL code.

 

·         Security factors.

[JeffRichter] The JIT compiler checks security link demands and inheritance demands when JIT compiling to see if it is allowed to JIT compile.

 

2.    What guarantees are there that the JIT compiler will produce the exact same executable every time it is run?  How can this be verified?

[JeffRichter] There is no guarantee that this will happen and, in fact, it frequently doesn’t happen. Debug code and release code is completely different, for example.

 

3.       With Strong named components what security testing has Microsoft done to ensure that another assembly can fake itself out to look like another assembly.

[JeffRichter] Strong-named assemblies are hashed and when the CLR loads them, it verifies the hash to ensure that no bits in the assembly have been changed. If a company’s private key is compromised (leaked), then there is no guarantee of security. Microsoft has tested the has algorithms and has modified strong-name assemblies to test they do not load.

 

Today, I discovered that Microsoft was filing a patent for “an operator that returns true when two memory addresses are not equal”!
 
 
Surely, we can still come up with better ideas than this to patent, can't we?
Plus, I think there is a lot of prior art around this particular invention.
Recently, I was at a customer site and they were comparing the performance of a function that was written in unmanaged C with its C# equivalent. As they expected, the C code was performing much faster than the C# code. However, I didn't expect this. Once managed code is JIT compiled, the code is very similar to that of unmanaged code. The code was being called in a loop in both versios numerous times so the additional time spent by the JIT compiler should be noise and I expect the performance of the C# code to be near identical and even better than the unmanaged C version because the JIT compiler could emit optimizations for the speciifc CPU architecture of the host machine.
 
I was very interested in this problem and I closely examined both functions. Not just the source code, but I also very closely examined the machine code generated by the unmanaged C compiler as well as the machine code generated by the .NET Framework's JIT compiler. Not surprising (to me), the machine code was pratically identical. I did see a place where the C compiler emitted an INCrement instruction where th JIT compiler emitted an ADD instruction to add 1. I assume that this is because the JIT compiler knew the host CPU and determined that an ADD instruction would be faster than an INCrement instruction. This would actually make the managed code version faster.
 
I also noticed a place where the unmanaged version was updating a register directly where the managed version was updating a indirect memory location. This was because the unmanaged source code was updating a local variable while the C# version was turned into an object-oriented equivalent and as updating a field in the class object. This difference alse seemed minor to me and could not possibly accounting for the performance discrepency we were seeing. However, we continued to examine the code and in an effort to get the emitted machine code to be identical between the 2 as possible, we got rid of the field in the object and turned it into a local variable instead. WOW! What a difference this made in performance!
 
Apparently, the JIT compiler is able to enregister local variables but it cannot enregister fields. This makes sense since a field can actually be manipulated by multiple threads simultaneously or via other means behind a method's back and therefore, the JIT compiler takes the safe route of not enregisterring the local and always saves and fetches its value from memory. On the other hand, a local variable cannot be modified behind a method's back and therefor the JIT compiler can put it in a register.
 
I always knew that memory access is slower than CPU register access but I guess I nenver really knew how big a difference it could be. On the machine we were using to test this, the differenece was about 8 times. That is, the method with the field ran 8 times slower than the equivalent method with the local variable! On my notebook computer, the difference was much less: the local variable version ran in ~25 seconds while the field version ran in ~31 seconds. Still a pretty big difference.
 
So, the moral of the story, is that you should avoid field access as much as possible in performance-sensitive code. It might even make sense to copy a field into a loca, use the local in the method and then copy the result back from the local into the field just before the method exits. Below is some simple code (that requires Whidbey because I'm using the Stopwatch class) that you can compile and test on your own machine to see the perf difference:
 
using System;
using System.Diagnostics;
 

class App {
 static void Main() {
  const Int64 iter = 5000000000;
 
  Stopwatch sw = Stopwatch.StartNew();
  TestLocalAccess(iter);
  Console.WriteLine("time taken:{0} ticks", sw.Elapsed);
 
  sw = Stopwatch.StartNew();
  TestFieldAccess(iter);
  Console.WriteLine("time taken:{0} ticks", sw.Elapsed);
 }
 
 private static Int64 j;
 
 public static void TestLocalAccess(Int64 numIncrement) {
  Int64 j=0;
  for(Int64 i=0; i<numIncrement; i++) j++;
 }
 
 public static void TestFieldAccess(Int64 numIncrement) {
  for(Int64 i=0; i<numIncrement; i++) j++;
 }
}
Last Thursday, a friend of mine from days gone by contacted me and invited me to a meeting. I met my friend when I started consulting for Microsoft about 12 yerars ago when he and I were both working on the first 32-bit version of Visual Studio (code name: “Barracuda”). Today, my friend works in the SPOT tema at MS. SPOT stands for Smart Personal Object Technology and their goals is to bring “intelligence” to everyday things. The first intelligent thing is the MSN Direct watches manuafactured by Fossil and others.
 
For these watches, Microsoft created a Tiny version of the CLR called, of course, TinyCLR. This is a version of the CLR that is smaller than the desktop version and even smaller than the Compact Framework version. It is the really tiner version and MS is able to put the TinyCLR on an integrated circuit running an ARM processor. This is what is in the watches today.  The watch also has an FM radio reciver in it and this is how it receives information over the air.
 
On Thursday, my friend, told me that MS was going to make the TinyCLR available as a microcontroller in Stamp form similar to the BASIC and Java Stamps that are available today. He gave me a demo where he wrote code in C# using Whidbey beta 1, downloaded the app to the TinyCLR Stamp on a circuit board connectged via serial cable to the PC and even used the Whidbey debugger to debug the code running on the stamp. I'll get some pictures posted soon of the TinyCLR Stamp and the circuit board.
 
Suffice it to say, I'm pretty jazzed about this and I can't wait to start playing around with it. I used to do electronics stuff when I was very, very young (like 10 years old) before I was introduced to computers. I've read all the documentation that comes with it so far and have downloaded some other documents from various web sites. This Monday, I leave for Devscovery Atlanta followed by a user group meeting in New York and some client visits (also in NY). So, I won't be home for a while -- the stamp will have to wait. I'm quite bummed. Maybe I'll write an MSDN Magazine article about the stamp and embedded CLR programming some day soon.
Last week was very hectic with Devscovery Redmond in full swing. It was a great event and I really think I connected with the audience. I had a lot of conversations between sessions and at the end of each day. In particular, during the reception, I had a whiteboard session where I was with 4 attendees architecting their client/server/web service architecture - what could be more fun than this?!
 
I also had 2 questions from attendees that I thought were interesting and caused me to write some code to verify how things worked. The first question was about delegates. The attendee asked if delegates work when the callback is to a virtual method. That night, I coded up the code below to test things out. Without peeking, can you guess what the output from this code is? “B: 34“ or “D: 34“?
 
using System;
 
class B {
   delegate String Del(Int32 x);
 
   static void Main() {
      B b = new D();
      Del del = new Del(b.M);
      Console.WriteLine(del(34));
   }
   protected virtual String M(Int32 x ) {
      return "B: " + x;
   }
}
 
class D : B {
   protected override String M(Int32 x) {
      return "D: " + x;
   }
}
 
The answer is “D: 34” as the delegate contains a reference to a D object and calling the instance method M DOES in fact happen polymorphically.
 
The second question was about the difference between System.Exception's Message property and its ToString method. I had forgotten what ToString on an Exception actually does so I used Lutz's Reflector to check the code for these two members. The Message property returns just the exception's message while ToString returns the class name, the Message text, the Stack trace, and repeats this for all nested exceptions too.
 
My next event is Devscovery Atlanta where, I'm sure I'll have just as much fun AND, I hope I learn some more while I'm there.
Oh, I forget to tell everyone that I was on episode #73 of .NET Rocks!
Check it out here.
 
By the way, I said in the show that Whidbey Click Once uses the BITS (code name “drizzle”) technology that has been in Windows for many years now. However, someone at Microsoft informed me that I was incorrect. In Whidbey, Click Once does not use BITS. However, in Orcas/Longhorn, Click Once will use BITS.
July 27th was my 40th birthday and Kristin, my wife, surprised me with an awesome present. First, she got her mother to babysit our son. Then, she contacted 6 of our friends and invited them to join us as we flew from Seattle to Coeur d'Alene Idaho. There she rented a van and we all drive to Silverwood Theme Park for a day of rollercoasters and water park slides! At the end of the day we drove to a resort for dinner with a great view and then we flew back to Seattle. What a great day! I love roller coasters. The wooden coaster, Tremors, at Silverwood is one of the best I've ever been on.
 
From Aug 2-4, I was in San Diego giving a 3-day .NET class. It was one of the largest turnouts we've ever had for a public seminar. It was a great class, very interactive. Wintellect is trying to set up another one of these in the Atlanta area around Sep 20th.
 
Every since the Tablet PC Devlab last month, I can't seem to get Tablet PC prgramming out of my head. I have this idea for a project that (slowly) I'm working on in my spare time. It's a program to help children learn how to print. The app creates a window where an adult can use the Tablet's stylus to print the upper- and lower-case letters A-Za-z in ink. The app splits all these strokes at their cusps and saves all of these strokes in a file. This is the “authoring“ phase. Then, after all the letters have been authored, the app can be re-run in the “runtime“ phase. In runtime pahse, a window is shown to a child and a letter is selected at random and shown to the child. The app shows the child how to draw the letter. This is done by slowly drawing each stroke of the letter in slow-motion. This is why I split the strokes of the letter into its cusps: each part of the stroke (before a turn) is drawn with a delay in between. Then, the child gets to draw the letter using the stylus and I send the child's strokes off to the recognizer. The recognizer tells me what letter it thinks the child drew and if it matches the randomly selected letter, then the child printed the character well enough to go on.
 
Anyway, this has been fun for me to play around with and it uses a fair amount of the facilities offered by the Tablet PC API. I'm still working on the authoring phase. I'm having trouble scaling and positioning the ink after it's authored into an ownerdraw listbox. I can't quite get thinks to line up correctly and I don't understand why. The API documentation may be lacking some important info for me to piece it all together. But, I'll get it.
 
Kristin & I have decided to go to Yosemite for a vacation. I probably won't be blogging while away.
 
When I get back, Jeff Prosise is coming out to Seattle and he and I are going to start re-doing the Wintellect web site in ASP.NET 2.0. This should be a great experience for both of us. The only problem is that I understand that Whidbey's ship date is slipping and we arent't allowed to “go live“ with the site until beta 2 ships. Since I have no idea when beta 2's ships, we may have to just hold on to the code for a while. And, I'm guessing we'll have to modify a bit to make it work with beta 2  before we “go live.“ But working with Jeff should be a blast; we plan to work very intently for 1 week on this.
 
Then, on August 31st starts the Devscovery conference in Redmond, WA. This will be the 2nd of 4 Devscovery conferences we've done. I always look forward to them and to interacting with the attendees.
 
Oh yea, one last thing: I'm hoping to fly to CA to see a concert. On Aug 28th, Jean Luc Ponty, Al DiMeola, and Stanley Clark are playing a jazz concert in Los Angeles. They produced a CD together about 10 years ago called Rites of Strings. I love this recording and am very excited to see that they have reformed to play it live.
 
 
 
More Posts Next page »