Bye bye 2004

It was quite an eventful year for me and there were various changes in my personal life as well as my professional life. The non-personal high-point this year was the MVP summit in Redmond – it’s probably the best way to see the Microsoft campus (at least a small part of it) without getting employed there :nerd:

There was also the event of selling my old Peugeot and getting a new Corolla (while the Corolla must be an everybody-has-one car in the western world, it’s pretty much a luxury for us Indians), and I still enjoy driving it around Trivandrum.

I have this funny feeling that 2005 is going to be even more eventful for me and I am expecting things to happen that will change the rest of my future life. Anyway, I don’t think the last post of 2004 should be a long one, so am winding up – or to be honest, I am just being plain lazy, which I guess I am allowed to do considering it’s new year’s eve ;-)

Happy New Year to all of you, my dearest blog readers, and thank you for all the nice comments and wishes you had sent my way through the blog.

pYear2004->ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0);

String interning, pointers and a dangerous side-effect

The CLR interns managed strings – this means that if the same string is used multiple times, all of them refer to the same instance of the string. This is possible because System::String is immutable – so the moment you change one of those strings, you are actually changing the reference which now refers to the new string (quite possibly another interned string). All this is fine as long as the strings are immutable. But, sometimes you can remove their immutability – when you use interior or pinning pointers to directly access the underlying character array. See the following code snippet :-

String^ s1 = "hello";
String^ s2 = "hello";

interior_ptr<Char> p1 = const_cast<interior_ptr<Char> >(
interior_ptr<Char> p2 = const_cast<interior_ptr<Char> >(

//modifying s2 through interior pointer p2
for(; *p2; *p2++='a');

//s1 and s2 are both "aaaaa"
Console::WriteLine("{0} and {1}",s1,s2);

We changed string s2 using the interior pointer p2, but because s2 and s1 are interned to the same string instance, we inadvertently change both the strings – s1 and s2. Nasty huh? Just for your information, string interning is done across AppDomains, so you might be changing strings all over the place and it might be a tough bug to figure out. So remember, when you play with strings using interior or pinned pointers, be careful, really careful.

The spell-checker conundrum

I used to be an excellent speller till I started using word processors and editors with built-in spell checking. Funnily, I never realized how profoundly my spelling abilities had deteriorated until very recently, when I had to write a letter by hand. I was horribly shocked to find that I wasn’t half-sure of the proper spelling for quite a few very commonly used words. Maybe its time to start writing by hand a few paragraphs every day before I become totally spelling-illiterate. Right now, I am trying to console myself by theorizing that I am not alone in this and that there must be 1000s of other miserable people out there, who have so got used to spell-checkers that they are totally unable to write three meaningful sentences without a bunch of spelling errors. :hmmm: