<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" gd:etag="W/&quot;A0AFSXo5fCp7ImA9WhRRFE4.&quot;"><id>tag:blogger.com,1999:blog-6434675</id><updated>2011-11-28T05:51:58.424+05:30</updated><category term="Windows Phone" /><category term="friend. adobe" /><category term="Team System" /><category term="travel" /><category term="S60" /><category term="Technology" /><category term="Everything Else" /><category term="Ruby" /><category term="Mango" /><category term="Software" /><category term="Garbage Collection" /><category term="Photography" /><category term="Coding / .NET" /><category term=".NET CF" /><category term="Fun" /><category term="Amazing India" /><category term="Silverlight" /><title>Geek Gyan</title><subtitle type="html">Travel with Abhinaba Basu to the depths of .NET Compact Framework</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>164</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/abhinaba/geekgyan" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="abhinaba/geekgyan" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>17.503355</geo:lat><geo:long>78.364046</geo:long><entry gd:etag="W/&quot;D0cARn84eCp7ImA9WhdaF0k.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-8608621334448876806</id><published>2011-10-28T01:20:00.001+05:30</published><updated>2011-10-28T01:20:47.130+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-10-28T01:20:47.130+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Mango" /><category scheme="http://www.blogger.com/atom/ns#" term="Coding / .NET" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><title>Windows Phone Mango: Under the hood of Fast Application Switch</title><content type="html">&lt;a href="http://www.flickr.com/photos/abhinaba/6161123133"&gt;&lt;img alt="spin" src="http://farm7.static.flickr.com/6062/6161123133_2b4c539bde_z.jpg"&gt;&lt;/a&gt;  &lt;p&gt;Fast Application Switch of FAS is kind of tricky for application developers to handle. There are a ton of documentation around how the developers need to handle the various FAS related events. I really liked the video &lt;a title="http://channel9.msdn.com/Events/DevDays/DevDays-2011-Netherlands/Devdays059" href="http://channel9.msdn.com/Events/DevDays/DevDays-2011-Netherlands/Devdays059"&gt;http://channel9.msdn.com/Events/DevDays/DevDays-2011-Netherlands/Devdays059&lt;/a&gt; which walks through the entire FAS experience (jump to around 8:30).&lt;/p&gt; &lt;p&gt;In this post I want to talk about how the CLR (Common Language Runtime or .NET runtime) handles FAS and what that means to your application. Especially the Active –&amp;gt; Dormant –&amp;gt; Active flow. Most of the documentation/presentation quickly skips over this with the vague “The application is made dormant”. This is equivalent to the “witches use brooms to fly”. What is the navigation mechanism or how the broom is propelled are the more important questions which no one seems to answer (given the time of year, I just couldn’t resist :P) . Do note that most developers can just follow the coding guidelines for FAS and never need to care about this. However, a few developers, especially the ones developing multi-threaded apps and using threading primitives may need to care about this. And hence this post&lt;/p&gt; &lt;h2&gt;Design Principle&lt;/h2&gt; &lt;p&gt;The entire Multi-threading design was made to ensure the following&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Principle 1: &lt;/strong&gt;Pre-existing WP7 apps shouldn’t break on Mango.&lt;br&gt;&lt;strong&gt;Principle 2: &lt;/strong&gt;When an application is sent to the background it shouldn’t consume any resources&lt;br&gt;&lt;strong&gt;Principle 3:&lt;/strong&gt; Application should be resumed fast (hence the name FAS)&lt;/p&gt; &lt;p&gt;As you’d see that these played a vital role in the design being discussed below.&lt;/p&gt; &lt;h2&gt;States&lt;/h2&gt; &lt;p&gt;The states an application goes through is documented in &lt;a title="http://msdn.microsoft.com/en-us/library/ff817008(VS.92).aspx" href="http://msdn.microsoft.com/en-us/library/ff817008(VS.92).aspx"&gt;http://msdn.microsoft.com/en-us/library/ff817008(VS.92).aspx&lt;/a&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;img title="Execution Model Diagram for Windows Phone 7.5" alt="Execution Model Diagram for Windows Phone 7.5" src="http://i.msdn.microsoft.com/dynimg/IC531037.png" width="421" height="536"&gt;&lt;/p&gt; &lt;h2&gt;CLR Design&lt;/h2&gt; &lt;p&gt;The diagram below captures the various phase that are used to rundown the application to make it dormant and later re-activated.&amp;nbsp; It gives the flow of an application as it goes through the Active –&amp;gt; Dormant –&amp;gt; Active state (e.g. the application was running and the user launches another application and then uses the back button to go back to the first application). &lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-La13tSpEJEk/Tqm2E3SyKqI/AAAAAAAAAYQ/8qi8yCqsKl4/s1600-h/image%25255B14%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-N61QmIKIvGc/Tqm2FBqmI9I/AAAAAAAAAYY/1MYdZCvwmbw/image_thumb%25255B8%25255D.png?imgmax=800" width="674" height="490"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;&lt;strong&gt;Deactivated&lt;/strong&gt;&lt;/h4&gt; &lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.deactivated(v=VS.92).aspx"&gt;Deactivated event&lt;/a&gt; is sent to the application to notify it that the user is navigating away from the application. After this there is 3 possible outcomes. It will either remain dormant, gets tombstoned or finally gets killed as well. Since there is no way to know which would happen, the application should store its transient state into the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage.state(v=VS.92).aspx"&gt;PhoneApplicationPage.State&lt;/a&gt; and it’s persistent state into some persistent store like the IsolatedStorage or even in the cloud. However, do note that the application has 10 seconds to handle the Deactivated event. In the 3 possible situations this is how the stored data will be used back&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Deactivate –&amp;gt; Dormant –&amp;gt; Active&lt;br&gt;In this situation the entire process was intact in memory and just it’s execution was stopped (more about it below). In the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.phoneapplicationservice.activated(v=VS.92).aspx"&gt;Activated&lt;/a&gt; event the application can just check the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.activatedeventargs.isapplicationinstancepreserved(v=VS.92).aspx"&gt;IsApplicationInstancePreserved&lt;/a&gt; property. If this is true then the application is coming back from Dormant state and can just use the in-memory state. Nothing needs to be re-read in.  &lt;li&gt;Deactivate –&amp;gt; Dormant –&amp;gt; Tombstoned –&amp;gt; Active&lt;br&gt;In this case the application’s in-memory state is gone. However, the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage.state(v=VS.92).aspx"&gt;PhoneApplicationPage.State&lt;/a&gt; is serialized back. So the application should read persistent user data from IsolatedStorage or other permanent sources in the Activated event. At the same time it case use the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage.state(v=VS.92).aspx"&gt;PhoneApplicationPage.State&lt;/a&gt; in the OnNavigatedTo event.  &lt;li&gt;Deactivate –&amp;gt; Dormant –&amp;gt; Terminated&lt;br&gt;This case is no different from the application being re-launched. So in the Launching event the user data needs to be re-created from the permanent store. &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.phoneapplicationpage.state(v=VS.92).aspx"&gt;PhoneApplicationPage.State&lt;/a&gt;&amp;nbsp; is empty in this case&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;The above supports the #1 principle of not breaking pre-existing WP7 apps. A WP7 app would’ve been designed without considering the dormant stage. Hence it would’ve just skipped the #1 option. So the only issue will be that a WP7 app will result in re-creating the application state each time and not get the benefit of the Dormant stage (it will get the performance of Tombstoning but not break in Mango).&lt;/p&gt; &lt;p&gt;Post this event the main thread never transitions to user code (e.g. no events are triggered). The requirement on the application for deactivate is that&lt;/p&gt; &lt;ol&gt; &lt;li&gt;It shouldn’t run any user code post this point. This means it should voluntarily stop background threads, cancel timers it started and so on  &lt;li&gt;This event needs to be handled in 10 seconds&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;If app continues to run code, e.g. in another thread and modifies any application state then that state cannot be persisted (as there will be no subsequent Deactivated type event)&lt;/p&gt; &lt;h4&gt;Paused&lt;/h4&gt; &lt;p&gt;This event is an internal event that is not visible to the application. If the application adhered to the above guideline it shouldn’t care about it anyway. &lt;/p&gt; &lt;p&gt;The CLR does some interesting stuff on this event. Adhering to the “no resource consumption” principle is very important. Consider that the application had used &lt;a href="http://msdn.microsoft.com/en-us/library/system.threading.manualresetevent(v=VS.95).aspx"&gt;ManualResetEvent&lt;/a&gt;.&lt;a href="http://msdn.microsoft.com/en-us/library/cc189907(v=VS.95).aspx"&gt;WaitOne&lt;/a&gt;(timeout). Now this timeout can expire in the time when the application was dormant. If that happened it would result in some code running when the application is dormant. This is not acceptable because the phone maybe behind locked screen and this context switch can get the phone out of a low-power state. To handle this the runtime detaches Waits, Thread.Sleep at Paused. Also it cancels all Timers so that no Timer callbacks happen post this Pause event.&lt;/p&gt; &lt;p&gt;Since Pause event is not visible to the application, it should consider that some time post Deactivated this detach will happen. &lt;strong&gt;This is completely transparent to user code&lt;/strong&gt;. As far as the user code is considered, it just that these handles do not timeout or sleeps do not return during the time the application is dormant. The same WaitHandle objects or Thread.Sleeps start working as is after the application is activated (more about timeout adjustment below). &lt;/p&gt; &lt;p&gt;This is also the place where other parts of the tear-down happens. E.g. things like asynchronous network calls cancelled, media is stopped.&lt;/p&gt; &lt;p&gt;Note that the background user threads can continue to execute. Obviously that is a problem because the user code is supposed to voluntarily stop them at Deactivated.&lt;/p&gt; &lt;h4&gt;Freeze&lt;/h4&gt; &lt;p&gt;Besides user code there are a lot of other managed code running in the system. These include but not limited to Silverlight managed code, XNA managed code. Sometime after Paused all managed code is required to stop. This is called the CLRFreeze. At this point the CLR freezes or blocks all managed execution including user background threads. To do that it uses the same mechanism as used for foreground GC. In a later post I’d cover the different mechanics NETCF and desktop CLR uses to stop managed execution.&lt;/p&gt; &lt;p&gt;Around freeze the application enters the Dormant stage where it’s in 0 CPU utilization mode.&lt;/p&gt; &lt;h4&gt;Thaw&lt;/h4&gt; &lt;p&gt;Managed threads stopped at Freeze are re-started at this point. &lt;/p&gt; &lt;h4&gt;Resuming&lt;/h4&gt; &lt;p&gt;At Resuming the WaitHandle, Thread.Sleep detached in Paused is re-attached. Also timeout adjustments are made during this time. Consider that the user had two handles on which the user code started Waits with 5 seconds and 10 seconds timeouts. After 3 seconds of starting the Waits the application is made dormant. When the application is re-activated, the Waits are restarted with the amount of timeout remaining at the point of the application getting deactivated. So essentially in the case below the first Wait is restarted with 2 seconds and the later with 7. This ensures that relative gap between Sleeps, Waits are maintained. &lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-tvtyT00oVEA/Tqm2FW1BrzI/AAAAAAAAAYg/8X6QUJhU6KU/s1600-h/image%25255B18%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-BcyTLfPDUTM/Tqm2Fm1BMhI/AAAAAAAAAYo/OgZhwzTyWmU/image_thumb%25255B10%25255D.png?imgmax=800" width="749" height="197"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Note timers are still not restarted.&lt;/p&gt; &lt;h4&gt;Activated&lt;/h4&gt; &lt;p&gt;This is the event that the application gets and it is required to re-build it’s state when the activation is from Tombstone or just re-use the state in memory when the activation is from Dormant stage.&lt;/p&gt; &lt;h4&gt;Resumed&lt;/h4&gt; &lt;p&gt;This is the final stage or FAS. This is where the CLR restarts the Timers. The idea behind the late start of timers is that they are essentially asynchronous callbacks. So the callbacks are not sent until the application is activated (built its state) and ready to consume those callbacks.&lt;/p&gt; &lt;h2&gt;Conclusion&lt;/h2&gt; &lt;ol&gt; &lt;li&gt;Ideally application developer needs to take care of the FAS by properly supporting the various events like Deactivated, Activated  &lt;li&gt;Background threads continue to run post the Deactivated event. This might lead to issues by corrupting application state and losing state changes. Handle this by terminating the background threads at Deactivated  &lt;li&gt;While making application dormant Waits, Sleeps and Timers are deactivated. They are later activated with timeout adjustments. This happens transparently to user code  &lt;li&gt;Not all waiting primitives are time adjusted. E.g. Thread.Join(timeout) is not adjusted. &lt;/li&gt;&lt;/ol&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-8608621334448876806?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/8608621334448876806/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=8608621334448876806&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/8608621334448876806?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/8608621334448876806?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2011/10/windows-phone-mango-under-hood-of-fast.html" title="Windows Phone Mango: Under the hood of Fast Application Switch" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm7.static.flickr.com/6062/6161123133_2b4c539bde_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A08AQ3oyfyp7ImA9WhdRFks.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-9036415733327986435</id><published>2011-08-02T11:57:00.001+05:30</published><updated>2011-08-07T04:00:42.497+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-08-07T04:00:42.497+05:30</app:edited><title>The C Word</title><content type="html">&lt;a href="http://www.flickr.com/photos/abhinaba/5315472412/"&gt;&lt;img alt="pic" src="http://farm6.static.flickr.com/5005/5315472412_afbab0dc9e_z.jpg"&gt;&lt;/a&gt;  &lt;p&gt;I have really thought a lot over posting this. This is a very personal post. I could either keep it to myself or share this to let others going through the same thing know it OK to be scared. &lt;strong&gt;&lt;font color="#ff0000"&gt;If you are here to read about programming and other fun stuff, go save yourself some time and skip this post.&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;The three week of wait&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;My wife was having a low-grade fever for 3 weeks. Unfortunately it coincided with a number of small symptoms. These made the spine specialist diagnose a slightly herniated disc, the internal medicine doctor diagnose some sort if infection and the allergist a drug related delayed allergy with Diclofenac given for the back-pain. Then later when nothing seemed to clear it up we were told its most likely an auto-immune disease. Test after test turned up negative results other than an elevated ESR and CPT. Apparently there was a inflammation going on inside her body. This is when we decided to cancel her home trip to India as the 24 hour travel was simply not possible with the back pain associated with the herniated disc.&lt;/p&gt; &lt;p&gt;All this while the doctor’s kept going by the book. I have a feeling this is something to do with the fact that doctors in the US are forced to be in a state of perfect equilibrium due to the opposing forces of law-suits from patients (doctor didn’t do enough) and push-back from insurance (doctor is doing too much). We were told time and again since her fever is not over 101F and it’s not been there for more than 3 weeks, there is no further testing required. Read up Mayo-clinic or Wikipedia on Fever of Unknown Origin and you’d see this as the criteria for getting concerned. However, my wife all the while could easily tell that something else is going on and she is feeling different. In other countries the doctors would have run at least a chest X-ray by this time. IMO the risk of additional radiation was easily worth it given her condition.&lt;/p&gt; &lt;p&gt;By this time we had seen 5 specialist and were waiting for the sixth, the rheumatologist to make the final diagnosis of some auto-immune disease. The spine specialist grudgingly decided to do an additional MRI (the second) of her entire pelvis. We went for that second MRI on Saturday 7/23/2011. Our primary care physician however, was worried. He kept calling us to enquire how she was feeling. While on the way back from the MRI, he called us up again and asked us to come on Monday, for further evaluation and maybe some full body scan. We could feel the edge in his voice. May god bless him for the care he showed.&lt;/p&gt; &lt;p&gt;We were learning that hardest part of being patients was really to have the patience.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;The end of wait&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;We went home and I asked my wife to try some Yoga breathing exercise, called Pranayama. She tried that and went to sleep. This is at this point we crossed the 3 weeks threshold and thankfully her fever crossed the 101F mark. Next day Sunday morning she felt worse and had a weird feeling in her chest and a huge rash on her leg. Really worried we rushed to the Bellevue Overlake ER room. &lt;/p&gt; &lt;p&gt;Within minutes her vitals were checked and she was put on a bed. The doctor re-diagnosed some auto-immune disease and setup an appointment for the next day. Then he did something which should’ve been done weeks earlier, ordered a chest X-ray. He left the room and went to casually check the x-ray, then came rushing back. &lt;/p&gt; &lt;p&gt;He asked my wife when she had the last X-ray. It was in 2007. The doctor’s face told us something is terribly wrong. He said there is a tumor in-between her heart and lungs. Clinically it looks like a &lt;a href="http://en.wikipedia.org/wiki/Lymphoma"&gt;Lymphoma&lt;/a&gt;. My wife responded by a &lt;a href="http://en.wikipedia.org/wiki/Vasovagal_syncope"&gt;Vasovagal response&lt;/a&gt;. Which essentially means she had a fit, fainted and her pressure hit 45/60 and pulse was at 40. Somehow for me everything slowed down, as if life was on slow-motion. I could process everything going around, I could talk to the doctor and figure out the next steps. No idea how I pulled that off. Our life changed at that very point. &lt;strong&gt;The C word entered our lives&lt;/strong&gt;. I thanked myself for asking her to do the breathing exercise, which exercised her lungs enough to show up the issue. Her left lung was only half opening due to the tennis ball sized tumor.&lt;/p&gt; &lt;p&gt;She had a CAT scan within 10 minutes. Now we had the 3D image of the tumor, it looked like a Lymphoma to the doctor. I sat with him for 15 minutes seeing the slides myself. I asked all the questions I could think off. Biopsies were ordered and we headed home, in stunned silence. She was only 34 and was perfectly healthy 3 weeks back, &lt;a href="http://geekgyan.blogspot.com/2011/07/palouse-photography-trip.html"&gt;travelling across Washington to Palouse&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;The kind words provided by the ER doctor provided too little to console my wife. However, I vaguely remember coming home, ordering a bunch of camera equipment for portrait photography and the Kindle version of the book &lt;a href="http://www.amazon.com/Emperor-All-Maladies-Biography-Cancer/dp/1439170916/ref=sr_1_1?ie=UTF8&amp;amp;qid=1311576568&amp;amp;sr=8-1"&gt;&lt;strong&gt;The Emperor of All Maladies: A Biography of Cancer&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;. &lt;/strong&gt;The book was recommended by the ER doctor while talking about how much cancer medicine has progressed. This is a Pulitzer winning work by another bong &lt;a href="http://www.amazon.com/Siddhartha-Mukherjee/e/B003SNL6EA/ref=ntt_athr_dp_pel_1"&gt;&lt;strong&gt;Siddhartha Mukherjee&lt;/strong&gt;&lt;/a&gt; (lets call him the BongDoctor) who seemed to have poor skills in choosing and hence studied in all of Stanford, Oxford, Columbia and Harvard.&lt;/p&gt; &lt;p&gt;I really have no idea why I bought those stuff and didn’t even remember the next day until I checked email that I have indeed ordered them.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Beginning of waiting again&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The very next day Monday 7/25/2011 the Oncologist called us, and he told that he has setup the first set of needle aspiration Biopsy. As my wife was in the Radiology room getting her Biopsy done, I got the phone call from the spine specialist. Remember he ordered a pelvic MRI on Friday. He started by saying he sees some abnormality on the sacral bone. I told him about the Lymphoma and he said, they should be related and asked for the contact info of our Oncologist. &lt;/p&gt; &lt;p&gt;So now Cancer has spread as well. For the first time in my life I publicly broke down sobbing un-controllably in the Overlake Hospital Café. I then rushed up to meet our oncologist for the first time and handed over the MRI discs to him.&lt;/p&gt; &lt;p&gt;Two days later on Wednesday 7/27/2011 we got to know that not enough tissue was available from the biopsy. They can see the abnormal cancer tissue but for further classification needs to have more. So Biopsy of the sacral bone was ordered as well. Thursday we got that done. The doctor called us many times letting us know of the progress and that the best lab in NW in Seattle is going through the slides. Finally we got the full diagnosis of &lt;a href="http://en.wikipedia.org/wiki/Hodgkin%27s_lymphoma"&gt;Nodular sclerosing Hodgkin’s Lymphoma&lt;/a&gt; and it’s Stage IV.&lt;/p&gt; &lt;p&gt;Then on advice from friends we looked up &lt;a href="http://www.seattlecca.org/"&gt;Seattle Cancer Care Alliance&lt;/a&gt; and we are going there for treatment. Right now they are relooking at all the cytology slides to re-confirm the disease and my wife is going through a bank of tests to ensure she is ready for the chemo that’s going to start in the next week. &lt;/p&gt; &lt;p&gt;My wife want’s to know why it took the most advanced medical system in the world, 4 weeks for the diagnosis, especially when the test required was just a chest X-ray. All the while 5 doctors chose to just wait around when she could exactly point with her finger the point on her spine where the second cancer tumor was. Why was it not caught in her last yearly exam? The reason was simple even the basic tests are not done in the US in yearly exams. I am sure it’s something to do with the costs. In India a yearly exam is extremely thorough. I am sure they go overboard and expose people to X-ray and such but in case this was still going on, it’d surely have been caught. &lt;/p&gt; &lt;p&gt;However, once this was diagnosed things started moving extremely swiftly. Doctors kept calling other doctors and pathologists. Multiple people were examining and cross examining the CT video and cytology slides. Doctors were calling us back to let us know of the progress and telling us to be brave.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;How are we coping&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;I have known my wife for the last 50% of my life. She was my high-school friend, and we fell in love just before moving onto college. Marrying high-school sweet heart has it pros and cons. She knows all my crushes and flings which I foolishly confided in a friend who turned into a wife later :). She has been there hand-holding and steering me through all the while. She stood beside me and continually, supported me as I rose from an average student in an unknown college to get into the top 10 in the university. I completed my BS-Physics and then chose Computer Science, she was beside me in the queue to submit the application. She was hanging out in the hotel lobby when I interviewed with Microsoft 7 years back in Delhi. She was always there.&lt;/p&gt; &lt;p&gt;After getting my first job in Texas Instruments I just couldn’t cope with the distance. We got married in 3 months and she joined me in Bangalore after 3 more months. We had by that time known each other for 6 years. Our 10th marriage anniversary is just 6 months away. We are going to hit 16 years of togetherness. In this time we have moved homes across 3 cities in India, moved across the oceans and settled in US. Had our daughter who is 6 year old. In this time she had lost her mother to cancer and I lost my father to COPD and my thyroid due to suspected cancer tumors. So we have/had a roller coaster ride, a ride we thoroughly enjoyed.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Role Reversal&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Now the roles have reversed. It’s now my turn to fight the battle and steer her through. Unfortunately the human body is not just a computer for which I could write a garbage collector to go cleanup all the garbage-cells. I am used to have all the nodes of the decision tree fully expanded. Mistakes usually involves retracing ones step and re-routing. Both of these don’t work in this situation.&lt;/p&gt; &lt;p&gt;However, I plan to be agile, do my research and work with the doctors to provide the best care my wife can get. I will surely learn a lot of lessons of life on the way&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Time to count the blessings&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;While I can crib about how life is unfair and how this shouldn’t be happening to me. But that doesn’t really add value. When I look around I can actually see a lot of blessings that’s been showered on us. I also learnt that this is the time to move pride out of the way and ask for help, there are so many around us who just need the cue to do something&lt;/p&gt; &lt;ol&gt; &lt;li&gt;We have had a great live together. Frankly there is no good time to get a disease like Cancer. It’s not as if at 60 we’d be ready. One is never ready and this timing is as bad as any other.  &lt;li&gt;Our daughter holds our sanity together. Whenever we get all bogged down she comes up with the weirdest question which becomes 3 times more funny when asked by someone missing 3 of her front teeth. &lt;li&gt;We literally haven’t cooked food for the last 4 weeks. There’s always been one neighbor or friend coming to our house with something to eat. People whom we know for barely weeks have been there for us. So it’s idly-sambhar for breakfast and paratha with Alloo-gobi in dinner.  &lt;li&gt;We have never have to get a sitter or drop our daughter to the day-care as we rush from one hospital to another, she has always been to one of her friends on a play-date, little aware of the turmoil we are going though.  &lt;li&gt;We just had to ask for a change of apartment (one with elevator access). The management team of the community we live in, attacked this issue with full force. They’ve made so many exceptions to make things easy for us, that I cannot thank them more  &lt;li&gt;Thankfully we chose to come to US. Worlds one of the best Cancer research center is just 30 minutes from here.  &lt;li&gt;I have one of the best employers in the world. Microsoft’s medical insurance have been phenomenal till now. I feel sad that it’s not going to be that great from 2013 (change in policy)  &lt;li&gt;My manager has been super supportive. I‘ve given many weekends and nights to work, to pull off deadlines. Now it seems so worthwhile.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;strong&gt;What am I asking for&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Nothing really. If you are religious, just pray to whomever you believe in to give us strength to pull us through. This post was just so that I can get this whole thing out of my system and concentrate on solving the issue at hand. If you are a friend or family just bear with me if I am suddenly withdrawn of plain irritating. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-9036415733327986435?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/9036415733327986435/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=9036415733327986435&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/9036415733327986435?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/9036415733327986435?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2011/08/c-word.html" title="The C Word" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm6.static.flickr.com/5005/5315472412_afbab0dc9e_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0QDR3s_fip7ImA9WhZaF04.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-4536015439301791843</id><published>2011-07-04T03:46:00.001+05:30</published><updated>2011-07-04T03:46:16.546+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-07-04T03:46:16.546+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Photography" /><category scheme="http://www.blogger.com/atom/ns#" term="travel" /><category scheme="http://www.blogger.com/atom/ns#" term="Everything Else" /><title>Palouse Photography Trip</title><content type="html">&lt;p&gt;From &lt;a href="http://en.wikipedia.org/wiki/Palouse"&gt;Wikipedia&lt;/a&gt;, “&lt;em&gt;The &lt;b&gt;Palouse&lt;/b&gt; is a region of the northwestern United States, encompassing parts of southeastern Washington, north central Idaho and, in some definitions, extending south into northeast Oregon. It is a major agricultural area, primarily producing wheat and legumes&lt;/em&gt;”. But that doesn’t really tell you what Palouse is :). My daughter named it more aptly as Greenland and the photo below is explanatory.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;a href="http://www.flickr.com/photos/abhinaba/5847348165/"&gt;&lt;img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://farm4.static.flickr.com/3386/5847348165_7fb740a1e3_z.jpg"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;It’s a beautiful land of rolling green (or Yellow based on season) hills and a photographer’s delight. It’s one of the most beautiful landscape I have ever seen. It’s easily worth the 5-6 hour drive from Western Washington cities like Seattle. The receptionist at the hotel we stayed in said that they’ve had photographers from as far as Australia visit them. &lt;/p&gt; &lt;p&gt;Last week (6/16/2011) I went on a 2 day trip to the Palouse area in Eastern Washington. The primary plan was to just drive around and take some great shots. This post captures the quick details about what went right, what went wrong and some tips about how to make the trip family friendly. &lt;/p&gt; &lt;h2&gt;&lt;strong&gt;Good Time to Visit&lt;/strong&gt;&lt;/h2&gt; &lt;p&gt;I asked around and checked Flickr for Palouse photos from different times of the year. I think early to mid June is pretty good time to see the excellent green colors in the field. August is great for capturing the golden yellow pre-harvest colors.&lt;/p&gt; &lt;h2&gt;&lt;strong&gt;Where to Go&lt;/strong&gt;&lt;/h2&gt; &lt;p&gt;My agenda was to cover Palouse water falls, the Colfax-Steptoe-Garfield-Palouse-Pullman pentagon. I took the &lt;a href="http://www.bing.com/maps/?v=2&amp;amp;cp=47.17461624069451~-119.95382948219775&amp;amp;lvl=7&amp;amp;dir=0&amp;amp;sty=u&amp;amp;rtp=pos.47.67856_-122.130994_Redmond%2C%20WA___e_~pos.46.663683516945525_-118.22733354475591_near%20Palouse%20Falls%20Rd%2C%20Kahlotus%2C%20WA%2099335___a_~pos.46.8794097751379_-117.36478485167026_Colfax%2C%20WA___e_~pos.46.78739238221032_-117.25586389669536_near%203386%20Albion%20Rd%2C%20Pullman%2C%20WA%2099163___a_~v.46.81399562304871_-117.19831301271907_Palouse%20Albion%20Rd~pos.46.84076743323181_-117.12417187162123_near%20Palouse%20Albion%20Rd%2C%20Palouse%2C%20WA%2099161___a_~pos.46.86898773159819_-117.15618694629297_near%20Kamiak%20Butte%20Park%20Rd%2C%20Palouse%2C%20WA%2099161___a_~pos.46.875800688039234_-117.22809317182333_near%209094%20S%20Palouse%20River%20Rd%2C%20Colfax%2C%20WA%2099111-8774___a_~pos.46.87941_-117.364785_Colfax%2C%20WA___a_~pos.47.03239_-117.29713_Steptoe%20Butte%2C%20WA___a_~pos.47.12890483438969_-117.24258944392204_Oakesdale%2C%20WA___e_~pos.47.09997315542195_-117.37421110554253_near%202010%20Oaksdale%20Rd%2C%20Oakesdale%2C%20WA%2099158___a_~v.47.12222915160441_-117.48128059397943_Sunset%20Rd~pos.47.300307_-117.974676_Sprague%2C%20WA___e_~pos.47.678414415583795_-122.12899341185616_15945%20NE%2085th%20St%2C%20Redmond%2C%20WA%2098052-3531___a_&amp;amp;mode=D&amp;amp;rtop=0~0~0~&amp;amp;form=LMLTCC"&gt;following route&lt;/a&gt;. Click around to see the main routes travelled.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.bing.com/maps/?v=2&amp;amp;cp=47.17461624069451~-119.95382948219775&amp;amp;lvl=7&amp;amp;dir=0&amp;amp;sty=u&amp;amp;rtp=pos.47.67856_-122.130994_Redmond%2C%20WA___e_~pos.46.663683516945525_-118.22733354475591_near%20Palouse%20Falls%20Rd%2C%20Kahlotus%2C%20WA%2099335___a_~pos.46.8794097751379_-117.36478485167026_Colfax%2C%20WA___e_~pos.46.78739238221032_-117.25586389669536_near%203386%20Albion%20Rd%2C%20Pullman%2C%20WA%2099163___a_~v.46.81399562304871_-117.19831301271907_Palouse%20Albion%20Rd~pos.46.84076743323181_-117.12417187162123_near%20Palouse%20Albion%20Rd%2C%20Palouse%2C%20WA%2099161___a_~pos.46.86898773159819_-117.15618694629297_near%20Kamiak%20Butte%20Park%20Rd%2C%20Palouse%2C%20WA%2099161___a_~pos.46.875800688039234_-117.22809317182333_near%209094%20S%20Palouse%20River%20Rd%2C%20Colfax%2C%20WA%2099111-8774___a_~pos.46.87941_-117.364785_Colfax%2C%20WA___a_~pos.47.03239_-117.29713_Steptoe%20Butte%2C%20WA___a_~pos.47.12890483438969_-117.24258944392204_Oakesdale%2C%20WA___e_~pos.47.09997315542195_-117.37421110554253_near%202010%20Oaksdale%20Rd%2C%20Oakesdale%2C%20WA%2099158___a_~v.47.12222915160441_-117.48128059397943_Sunset%20Rd~pos.47.300307_-117.974676_Sprague%2C%20WA___e_~pos.47.678414415583795_-122.12899341185616_15945%20NE%2085th%20St%2C%20Redmond%2C%20WA%2098052-3531___a_&amp;amp;mode=D&amp;amp;rtop=0~0~0~&amp;amp;form=LMLTCC"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/-0D9IsVhqrdE/ThDqLmHfafI/AAAAAAAAAXs/RNOWfzE63rs/image4.png?imgmax=800" width="1233" height="426"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h3&gt;&lt;strong&gt;On the Way&lt;/strong&gt;&lt;/h3&gt; &lt;p&gt;&lt;a href="http://www.flickr.com/photos/abhinaba/5847896088/"&gt;&lt;img style="margin: 0px 0px 0px 6px; display: inline; float: right" border="0" alt="Palouse waterfall" align="right" src="http://farm3.static.flickr.com/2466/5847896088_dd632b7417_m.jpg" width="160" height="240"&gt;&lt;/a&gt;On the way (and back) you should stop at the great I90 rest areas. They are spread around every 30-40miles and there are blue signs on the way indicating where they are (e.g. Rest Area Next Right) and how far the next one is (Next Rest Area 34 miles). Many of these serve free free hot coffee and cookies and all of them have rest rooms. After gorging on the super hot coffee and home made cookies made by dear old ladies who run these places, do remember to generously donate in the donation boxes. We carried our camping stove and had some nice warm noddle soup for lunch at the rest area.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.flickr.com/photos/abhinaba/5847339379/"&gt;&lt;img style="margin: 0px 6px 0px 0px; display: inline; float: left" border="0" alt="Palouse waterfall, furry friend" align="left" src="http://farm6.static.flickr.com/5261/5847339379_9e109f7f32_m.jpg" width="240" height="163"&gt;&lt;/a&gt;We then stopped at the Palouse falls (B in the map). As with most remote sites with dirt roads, the GPS picked up some really bad roads for the routing (Nunamaker Rd). Avoid this road and follow the signs and the route showed in the map which is to avoid Nunamaker Rd and continue straight on 260 and take a left onto 261. This goes into the Palouse Falls State Park. The Park has around 10 campsites and has a huge waterfall plummeting down 190ft. Covered picnic shelter with tables, water and barbeque pits are available here. The camp sites are first come only and there is a resident host as well. There is water but no power hookup at the sites. There are some short &lt;a href="http://www.wta.org/go-hiking/hikes/palouse-falls"&gt;hiking opportunities&lt;/a&gt; as well where you can hike 0.5 miles up towards the waterfall top. However, do note that the hiking routes have some points where there is significant exposure to heights and you gotta be very careful. There is also no safe way to descend to the bottom of the falls even though there seems to be some trails that go down.&lt;/p&gt; &lt;p&gt;There are a lot of cute Marmots and a lot of huge insects and snakes all around. &lt;/p&gt; &lt;h3&gt;The Palouse&lt;/h3&gt; &lt;p&gt;&lt;a href="http://www.flickr.com/photos/abhinaba/5847936360/"&gt;&lt;img style="margin: 0px 6px 0px 0px; display: inline; float: left" border="0" alt="Palouse Old barn" align="left" src="http://farm6.static.flickr.com/5115/5847936360_0014cce440_m.jpg" width="240" height="160"&gt;&lt;/a&gt;We didn’t stay in the Falls area. Instead we went ahead to Colfax which is around an hour away. I really liked the &lt;a href="http://book.bestwestern.com/bestwestern/US/WA/Colfax-hotels/BEST-WESTERN-PLUS-Wheatland-Inn/Hotel-Overview.do?propertyCode=48170"&gt;Best Western Wheatland Inn&lt;/a&gt; at Colfax where we stayed. We paid around $110 for the night. It had a nice hot breakfast, good rooms with TV and a nice warm indoor swimming pool. I cared about these because my wife and kid would spend a lot of time indoors as I’d drive around on the dirt roads for the next day or so. Just opposite to the hotel was a store, Taco Bell, Subway and other eating joints. I have had other friends who stayed in Pullman (30mins south of Colfax) which has many more hotel options because it’s the house to Washington State University. However, I ‘d recommend staying in Colfax due to it’s proximity to Steptoe butte and other interesting areas.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.flickr.com/photos/abhinaba/5847350527/"&gt;&lt;img style="display: inline; float: right" border="0" alt="Palouse from Steptoe Butte" align="right" src="http://farm6.static.flickr.com/5030/5847350527_505934d620_m.jpg" width="160" height="240"&gt;&lt;/a&gt;After checking in I went to the &lt;a href="http://en.wikipedia.org/wiki/Steptoe_Butte"&gt;Steptoe Butte&lt;/a&gt; for the customary Sunset shot, which however was utterly ruined due to rains and clouds. Steptoe Butte is a very important geological feature and a must visit. So much so that other geological features of it’s type is called steptoes. Steptoe is a 400 million year old rock sticking up high over the rolling hills of Palouse. Amazing views of light and shadow on the Palouse and patterns of wheat harvest can be seen from top.&lt;/p&gt; &lt;p&gt;Post sunset I got back to the hotel. Next day morning I mainly drove around inside the Pentagon. Then came back for some lunch in the hotel. Then again after some driving around headed back via I90.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.flickr.com/photos/abhinaba/5847346471/"&gt;&lt;img style="margin: 0px 6px 0px 0px; display: inline; float: left" border="0" alt="Palouse run down barn" align="left" src="http://farm3.static.flickr.com/2621/5847346471_63f534d714_m.jpg" width="240" height="160"&gt;&lt;/a&gt;To drive around the key thing to remember is that all state routes have almost no shoulders and no place to stop. So even if one route offers a good view, you cannot stop to photograph. Also the broken down barns are not really on the main routes. So you need to pick up the dirt roads and drive on them. These are gravel roads and cars skid a lot on them. So a 4x4 car is a good thing to have but not really mandatory. The route I mainly drove on is in the map linked above. However, they show the main route taken, you’d need to continually divert from them to get to the side roads as well. &lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;a href="http://www.flickr.com/photos/abhinaba/5847909818/"&gt;&lt;img style="display: inline; float: right" border="0" alt="Palouse colors" align="right" src="http://farm6.static.flickr.com/5190/5847909818_ef0d9ef38d_m.jpg" width="240" height="160"&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Some nice roads to try&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Palouse Alboin Road. Get into the side roads for broken garages and barns  &lt;li&gt;I tried and really liked the Chief Kamiakin Park &amp;gt;Fugate Road &amp;gt; S Palouse River Rd. However,  &lt;li&gt;Hume Road (From SR 195 to Oaksdale) &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;The photographs at &lt;a title="http://www.flickr.com/photos/abhinaba/sets/72157626870022427" href="http://www.flickr.com/photos/abhinaba/sets/72157626870022427"&gt;http://www.flickr.com/photos/abhinaba/sets/72157626870022427&lt;/a&gt; are manually geocoded, so that should give an approximate idea on where they were taken.&lt;/p&gt; &lt;h3&gt;The Way Back&lt;/h3&gt; &lt;p&gt;We came back via a different route because we were already close to Oakesdale and were told that the road from there to I90 had some nice views. We took the Oakesdale &amp;gt; Thornton &amp;gt; St. John &amp;gt; Sprague &amp;gt; Seattle via I90 West route.&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.flickr.com/photos/abhinaba/5847341973/"&gt;&lt;img style="margin: 0px 6px 0px 0px; display: inline; float: left" border="0" alt="Palouse farming planes" align="left" src="http://farm4.static.flickr.com/3282/5847341973_8c0bb3f3fb_m.jpg" width="240" height="160"&gt;&lt;/a&gt;We did make some stops on the way back. One was the scenic viewpoint just before crossing the Columbia river gorge. The other was the &lt;a href="http://en.wikipedia.org/wiki/Ginkgo/Wanapum_State_Park"&gt;Ginkgo Petrified Forest&lt;/a&gt; State Park Visitor center. This is just after the gorge. It contains some fantastic samples of &lt;a href="http://en.wikipedia.org/wiki/Petrifaction"&gt;petrified&lt;/a&gt; tree trunks where Ginkgo trees have been transformed to rocks (silica) after being covered by lava flows some 15 million years back. Also from the interpretive center you can see the banks of the Columbia river. We had some fun counting the layers of Lava visible on the banks where each layer corresponds to a major lava-flow incident millions of years back.&lt;/p&gt; &lt;h3&gt;Back Home&lt;/h3&gt; &lt;p&gt;The trip was awesome and covered 400 million year old rocks, 15 million year old tree trucks, 3 month old crops and everything in between. I plan to go back again to capture the Golden hues of the pre-harvest crops soon.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-4536015439301791843?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/4536015439301791843/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=4536015439301791843&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/4536015439301791843?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/4536015439301791843?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2011/07/palouse-photography-trip.html" title="Palouse Photography Trip" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm4.static.flickr.com/3386/5847348165_7fb740a1e3_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A0UBQ3c5cSp7ImA9WhZbGEo.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-5660203283972161999</id><published>2011-06-24T03:08:00.001+05:30</published><updated>2011-06-24T07:04:12.929+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-24T07:04:12.929+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Everything Else" /><title>Secure Conversion of your personal Microsoft Office Documents to Kindle</title><content type="html">&lt;a href="http://www.flickr.com/photos/abhinaba/5847341973/in/photostream"&gt;&lt;img alt="Farming plane in Palouse, WA" src="http://farm4.static.flickr.com/3282/5847341973_8c0bb3f3fb_z.jpg"&gt;&lt;/a&gt;  &lt;p&gt;I love my &lt;a href="http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&amp;amp;field-keywords=kindle+3"&gt;Kindle 3&lt;/a&gt; and really enjoy it’s readability and portability. However, a lot of my reading is confidential docs and papers which don’t come off the Kindle store. I had to spend some time to figure out the best way to get those onto Kindle securely. Since I use the latest Microsoft document formats (docx) a bunch of the commonly referred tools like Calibre didn’t work for me.&lt;/p&gt; &lt;p&gt;In case you are not worried about security and do not mind sending your document to Amazon for free conversion and transfer to your kindle, then just visit &lt;a title="http://www.amazon.com/gp/help/customer/display.html?nodeId=200375630" href="http://www.amazon.com/gp/help/customer/display.html?nodeId=200375630"&gt;http://www.amazon.com/gp/help/customer/display.html?nodeId=200375630&lt;/a&gt; and thanks for stopping by on this blog &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://lh3.ggpht.com/-z3lWFrnKvBw/TgOyRsrVGlI/AAAAAAAAAXA/Ho_qB7DVTxQ/wlEmoticon-smile%25255B2%25255D.png?imgmax=800"&gt;&lt;/p&gt; &lt;p&gt;However, in case the document is confidential and you don’t want to send it to Amazon read on&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Using PDF&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Kindle 3 supports PDF natively. So you can just transfer a PDF to it by connecting the Kindle to your PC over USB. Save the document to pdf using say Microsoft office save to PDF (File –&amp;gt; Save As (format PDF)) and then attach your kindle to the PC, it will show up as a Removable Storage drive and you can copy the PDF to it.&lt;/p&gt; &lt;p&gt;However, the document might turn out with tiny text and you’d need to scroll all around on the Kindle to view it. This is far from being acceptable and I use the following steps to get around that. &lt;/p&gt; &lt;p&gt;Install CurePDF writer from &lt;a title="http://cutepdf.com/Products/CutePDF/writer.asp" href="http://cutepdf.com/Products/CutePDF/writer.asp"&gt;http://cutepdf.com/Products/CutePDF/writer.asp&lt;/a&gt;. This installs a virtual printer to your PC called “CutePDF Writer”. Now print any document to this printer (File –&amp;gt; Print) and it will create a pdf file on your computer. While printing I use the following settings &lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-pLKAdxhcI7A/TgOyR1K8gDI/AAAAAAAAAXE/LPGnmmC0MZA/s1600-h/image%25255B3%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-wnKG0PYfy4c/TgOySH-PxPI/AAAAAAAAAXI/bJjnnyHg54Y/image_thumb%25255B1%25255D.png?imgmax=800" width="302" height="498"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I use a small page size of A6 to ensure good readability on the Kindle. Once you click on the Print button CutePDF shows a file save as dialog using which you can directly point it to the attached Kindle storage drive. Experiment for what page size works best for the particular kind of document and Kindle you have (plain vs Dx).&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Using MobiPocket Creator&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Download MobiPocket Creator from &lt;a title="http://www.mobipocket.com/en/DownloadSoft/ProductDetailsCreator.asp" href="http://www.mobipocket.com/en/DownloadSoft/ProductDetailsCreator.asp"&gt;http://www.mobipocket.com/en/DownloadSoft/ProductDetailsCreator.asp&lt;/a&gt;.&amp;nbsp; Launch MobiPocket and then click on Import –&amp;gt; MS Word Document&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/-eq2PhH8ugEg/TgOySMSuTFI/AAAAAAAAAXM/HTnf8MbGRA4/s1600-h/image%25255B7%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-4kj6sfDnTvs/TgOyS7Ck5vI/AAAAAAAAAXQ/ifUa4_xGNpA/image_thumb%25255B3%25255D.png?imgmax=800" width="328" height="166"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Use the browse button to choose the document, in the file open dialog choose the document. However, do note that you may need to change the File type filter to *.* and not *.doc if you are opening the latest docx format&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-WkwKHAUExts/TgOyTI4l5HI/AAAAAAAAAXU/mRoNA78BEc4/s1600-h/image%25255B12%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-wzr-LPMeJgM/TgOyTfFETmI/AAAAAAAAAXY/VGGJTxmtKQ4/image_thumb%25255B6%25255D.png?imgmax=800" width="519" height="135"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Once you have selected the document click on Import. This will get the document imported to MobiPocket.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-tGDqgkScJVg/TgPpkyOU7AI/AAAAAAAAAXk/NbxSUWJ7xbA/s1600-h/image%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/-eZnlglyEnzg/TgPplCLEEcI/AAAAAAAAAXo/GvOAUo68xtg/image_thumb%25255B1%25255D.png?imgmax=800" width="527" height="228"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Click on Build and then “Open folder containing eBook” and click OK. From the folder that opens copy the *.opf and *.prc to the Kindle’s document folder. Detach the kindle from the PC. The document should show up on the Kindle home screen.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-5660203283972161999?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/5660203283972161999/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=5660203283972161999&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/5660203283972161999?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/5660203283972161999?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2011/06/secure-conversion-of-your-personal.html" title="Secure Conversion of your personal Microsoft Office Documents to Kindle" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm4.static.flickr.com/3282/5847341973_8c0bb3f3fb_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CUQGQX4yfCp7ImA9WhZbEEo.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-1604415074060861503</id><published>2011-06-14T23:12:00.000+05:30</published><updated>2011-06-14T23:12:00.094+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-14T23:12:00.094+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Coding / .NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Garbage Collection" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><title>WP7 Mango: The new Generational GC</title><content type="html">&lt;a href="http://www.flickr.com/photos/abhinaba/5679209348/in/photostream"&gt;&lt;img src="http://farm6.static.flickr.com/5141/5679209348_b26f98d392_z.jpg"&gt;&lt;/a&gt;  &lt;p&gt;In my previous post “&lt;a href="http://blogs.msdn.com/b/abhinaba/archive/2011/06/08/wp7-mango-mark-sweep-collection-and-how-does-a-generational-gc-help.aspx"&gt;Mark-Sweep collection and how does a Generational GC help&lt;/a&gt;” I discussed how a generational Garbage Collector (GC) works and how it helps in reducing collection latencies which show up as long load times (startup as well as other load situations like game level load) and gameplay or animation jitter/glitches. In this post I want to discuss how those general principles apply to the WP7 Generational GC (GenGC) specifically. &lt;/p&gt; &lt;h2&gt;Generations and Collection Types&lt;/h2&gt; &lt;p&gt;We use &lt;strong&gt;2 generations on the WP7 &lt;/strong&gt;referred to as Gen0 and Gen1. A collection could be any of the following 4 types&lt;/p&gt; &lt;ol&gt; &lt;li&gt;An ephemeral or Gen0 collection that runs frequently and only collects Gen0 objects. Object surviving the Gen0 collection is promoted to Gen1  &lt;li&gt;Full mark-sweep collection that collects all managed objects (both Gen1 and Gen0)  &lt;li&gt;Full mark-sweep-compact collection that collects all managed objects (both Gen1 and Gen0)  &lt;li&gt;Full-GC with &lt;a href="http://blogs.msdn.com/b/abhinaba/archive/2009/04/17/net-code-pitching.aspx"&gt;code-pitch&lt;/a&gt;. This is run under severe low memory and can even throw away JITed code (something that desktop CLR doesn’t support) &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;The list above is in the order of increasing latency (or time they take to run)&lt;/p&gt; &lt;h2&gt;Collection triggers&lt;/h2&gt; &lt;p&gt;GC triggers are the same and as outlined in my previous post &lt;a href="http://blogs.msdn.com/b/abhinaba/archive/2010/07/29/windows-phone-7-app-development-when-does-the-gc-run.aspx"&gt;WP7: When does the GC run&lt;/a&gt;. The distinction between #2 and #3 above is that at the end of all full-GC the collector considers the memory fragmentation and can potentially run the memory compactor as well. &lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;After significant allocation&lt;/strong&gt; &lt;br&gt;After significant amount of managed allocation the GC is started. The amount today is 1MB (called &lt;a href="http://blogs.msdn.com/b/abhinaba/archive/2009/03/23/net-compact-framework-gc-quantum.aspx"&gt;GC quanta&lt;/a&gt;) but is open to change. This GC can be ephemeral or full-GC. In general it’s an ephemeral collection. However, it might be a full collection under the following cases  &lt;ol&gt; &lt;li&gt;After significant promotion of objects from Gen0 to Gen1 the collections become full collections. Today 5MB of promotion triggers a full GC (again this number is subject to change).  &lt;li&gt;Application’s total memory usage is close to the maximum memory cap that apps have (very little free memory left). This indicates that the application will get terminated if the memory utilization is not cut-back.  &lt;li&gt;Piling up of native resources. We use different heuristics like native to managed memory ratio and finalizer queue heuristics to detect if GC needs to turn to full collection to release native resources being held-up due to Gen0 only collections &lt;/li&gt;&lt;/ol&gt; &lt;li&gt;&lt;strong&gt;Resource allocation failure&lt;/strong&gt; &lt;br&gt;All resource allocation failure means that the system is under memory pressure and hence such collections are always full collection. This can lead to code pitch as well  &lt;li&gt;&lt;strong&gt;User code triggered GC&lt;/strong&gt; &lt;br&gt;User code can start collections via the &lt;a href="http://msdn.microsoft.com/en-us/library/xe0c2357(v=VS.95).aspx"&gt;System.GC.Collect()&lt;/a&gt; managed API. This results in a full collection as documented by that API. We have not added the method overload &lt;a href="http://msdn.microsoft.com/en-us/library/y46kxc5e.aspx"&gt;System.GC.Collect(generation)&lt;/a&gt;. Hence there is no way for the developer to start a ephemeral or Gen0 only collection  &lt;li&gt;&lt;strong&gt;Sharing server initiated&lt;/strong&gt; &lt;br&gt;&lt;a href="http://blogs.msdn.com/b/abhinaba/archive/2010/04/28/we-believe-in-sharing.aspx"&gt;Sharing server&lt;/a&gt; can detect phone wide memory issue and start GC in all managed processes running. These are full-GC and can potentially pitch code as well. &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;So from all of the above, the 3 key takeaways are&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Low memory or memory cap related collections are always full-collections. These could also turn out to be the more costly compacting collection and/or pitch JITed code  &lt;li&gt;Collections are in general ephemeral and become full-collection after significant object promotion  &lt;li&gt;No fundamental changes to the GC trigger policies. So an app written for WP7 will not see any major changes to the number of GC’s that happen. Some GC will be ephemeral and others will be full-GCs. &lt;/li&gt;&lt;/ol&gt; &lt;h2&gt;&amp;nbsp;&lt;/h2&gt; &lt;h2&gt;Write Barriers/Card-table&lt;/h2&gt; &lt;p&gt;As explained in my previous post, to keep track of Gen1 to Gen0 reference we use write-barrier/card-table. &lt;/p&gt; &lt;p&gt;Card-table can be visualized as a memory bitmap. Each bit in the card-table covers n bytes of the net address space. Each such bit is called a Card. For managed reference updates like&amp;nbsp; &lt;font face="Courier New"&gt;A.b = C&lt;/font&gt; in addition to JITing the real assignment, calls are added to Write-barrier functions. This&amp;nbsp; write barrier locates the Card corresponding to the address of write and sets it. Later during collection the collector checks all Gen-1 objects covered by a set card-bit and marks Gen-0 references in those objects. &lt;/p&gt; &lt;p&gt;This essentially brings in two additional cost to the system.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Memory cost of adding those calls to the WB in the JITed code  &lt;li&gt;Cost of executing the write barrier while modifying reference &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Both of the above are optimized to ensure they have minimum execution impact. We only JIT calls to WB when absolutely required and even then we have an overhead of a single instruction to make the call. The WB are hand-tuned assembly code to ensure they take minimum cycles. In effect the net hit on process memory due to write barriers is way less than 0.1%. The execution hit in real-world applications scenarios is also not in general measureable (other than real targeted testing). &lt;/p&gt; &lt;h2&gt;Differences from desktop&lt;/h2&gt; &lt;p&gt;In principle both the desktop GC and the WP7 GC are similar in that they use mark-sweep generational GC. However, there are differences based on the fact that the WP7 GC targets a more constrained device.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;2 generations as opposed to 3 on the desktop  &lt;li&gt;No background or incremental collection supported on the phone  &lt;li&gt;WP7 GC has additional logic to track and handle application policies like application memory caps and total memory utilization  &lt;li&gt;The phone CLR uses a very different memory layout which is pooled and not linear. So no concept of &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc534993.aspx"&gt;Large Object Heap&lt;/a&gt;. So lifetime of large objects is no different  &lt;li&gt;No support for particular generation collection from user code&lt;/li&gt;&lt;/ol&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-1604415074060861503?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/1604415074060861503/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=1604415074060861503&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/1604415074060861503?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/1604415074060861503?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2011/06/wp7-mango-new-generational-gc.html" title="WP7 Mango: The new Generational GC" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm6.static.flickr.com/5141/5679209348_b26f98d392_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CkIHQ3o-eSp7ImA9WhZUFUU.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-8656817271632112164</id><published>2011-06-09T06:18:00.001+05:30</published><updated>2011-06-09T06:18:52.451+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-09T06:18:52.451+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Coding / .NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Garbage Collection" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><category scheme="http://www.blogger.com/atom/ns#" term="Software" /><title>WP7 Mango: Mark-Sweep collection and how does a Generational GC help</title><content type="html">&lt;a src="http://www.flickr.com/photos/abhinaba/5663301171/" alt="tulips"&gt;&lt;img src="http://farm6.static.flickr.com/5265/5663301171_692ae168e2_z.jpg"&gt;&lt;/a&gt;  &lt;p&gt;About a month back we &lt;a href="http://blogs.msdn.com/b/abhinaba/archive/2011/04/13/generational-gc-in-windows-phone-mango.aspx"&gt;announced&lt;/a&gt; that in the next release of Windows Phone 7 (codenamed Mango) we will ship a new garbage collector in the CLR. This garbage collector (GC) is a generational garbage collector. &lt;/p&gt; &lt;p&gt;This post is a “&lt;strong&gt;back to basics&lt;/strong&gt;” post where I’ll try to examine how a mark-sweep GC works and how adding generational collection helps in boosting it’s performance. We will take a simplified look at how mark-sweep-compact GC works and how generational GC can enhance it’s performance. In later posts I’ll try to elaborate on the specifics of the WP7 generational GC and how to ensure you get the best performance out of it.&lt;/p&gt; &lt;h2&gt;Object Reference Graph&lt;/h2&gt; &lt;p&gt;Objects in the memory can be considered to be a graph. Where every object is a node and the references from one object to another are edges. Something like&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-npW8kHSwJC0/TfAYZ_IYaRI/AAAAAAAAAU8/z2VTjlPf940/s1600-h/image%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-td_r_974ipM/TfAYZzZ1gpI/AAAAAAAAAVA/oVu78U3Z8uE/image_thumb%25255B2%25255D.png?imgmax=800" width="450" height="201"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;To use an object the code should be able to “reach” it via some reference. These are called reachable objects (in blue). Objects like a method’s local variable, method parameters, global variables, objects held onto by the runtime (e.g. GCHandles), etc. are directly reachable. They are the starting points of reference chains and are called the roots (in black). &lt;/p&gt; &lt;p&gt;Other objects are reachable if there are some references to them from roots or from other objects that can be reached from the roots. So Object4 is reachable due to the Object2-&amp;gt;Object4 reference. Object5 is reachable because of Object1-&amp;gt;Object3-&amp;gt;Object5 reference chain. All reachable objects are valid objects and needs to be retained in the system.&lt;/p&gt; &lt;p&gt;On the other hand Object6 is not reachable and is hence garbage, something that the GC should remove from the system.&lt;/p&gt; &lt;h2&gt;Mark-Sweep-Compact GC&lt;/h2&gt; &lt;p&gt;A garbage collector can locate garbage like Object6 in various ways. Some common ways are &lt;a href="http://blogs.msdn.com/b/abhinaba/archive/2009/01/27/back-to-basics-reference-counting-garbage-collection.aspx"&gt;reference-counting&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/abhinaba/archive/2009/02/02/back-to-basics-copying-garbage-collection.aspx"&gt;copying-collection&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/abhinaba/archive/2009/01/30/back-to-basics-mark-and-sweep-garbage-collection.aspx"&gt;Mark-Sweep&lt;/a&gt;. In this section lets take a more pictorial view of how mark-sweep works.&lt;/p&gt; &lt;p&gt;Consider the following object graph&lt;/p&gt; &lt;h3&gt;&lt;/h3&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-FJFjZM97cHs/TfAYaDAkUxI/AAAAAAAAAVE/4FEqgzlVg0s/s1600-h/1%25255B5%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="1" border="0" alt="1" src="http://lh3.ggpht.com/-_kUL_LPSEJ4/TfAYaZGpaMI/AAAAAAAAAVI/yL93HOUE7X4/1_thumb%25255B3%25255D.png?imgmax=800" width="494" height="182"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;At first the GC pauses the entire application so that the object graph is not being mutated (as in no new objects or references are being created). Then it goes into the mark phase. In mark phase the GC traverses the graph starting at the roots and following the references from object to object. Each time it reaches an object through a reference it flips a bit in the object header indicating that this object is marked or in other words reachable (and hence not garbage). At the end everything looks as follows&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-e8OXhKBl-Rk/TfAYadx7oRI/AAAAAAAAAVM/Ch6z5ibnZkw/s1600-h/2%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="2" border="0" alt="2" src="http://lh4.ggpht.com/-2ZOGDzdtEQY/TfAYawRwSZI/AAAAAAAAAVQ/0Dr60qTN17c/2_thumb%25255B2%25255D.png?imgmax=800" width="492" height="173"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;So the 2 roots and the objects A, C, D are reachable.&lt;/p&gt; &lt;p&gt;Next it goes into the sweep phase. In this phase it starts from the very first object and examines the header. If the header’s mark bit is set it means that it’s a reachable object and the sweep resets that bit. If the header’s bit is not set, it’s not reachable and is flagged as garbage.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-gHzEzS2NSEw/TfAYbKciy6I/AAAAAAAAAVU/Rf7as0EpKFk/s1600-h/3%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="3" border="0" alt="3" src="http://lh3.ggpht.com/-Mq28i_VBuLI/TfAYbGGGncI/AAAAAAAAAVY/5LkiMu10kig/3_thumb%25255B2%25255D.png?imgmax=800" width="493" height="188"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;So B and E gets flagged as garbage. Hence these areas are free to be used for other objects or can be released back to the system&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/-d9Gn9mYFf70/TfAYbRxqF1I/AAAAAAAAAVc/TKfjsaAmK8k/s1600-h/4%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="4" border="0" alt="4" src="http://lh6.ggpht.com/-01QW9AT9foY/TfAYbmqD81I/AAAAAAAAAVg/_19EatUKh2M/4_thumb%25255B2%25255D.png?imgmax=800" width="493" height="174"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is where the GC is done and it may resume the execution of the application. However, if there are too many of those holes (released objects) created in the system, then the memory gets fragmented. To reduce memory fragmentation. The GC &lt;u&gt;may&lt;/u&gt; compact the memory by moving objects around. Do note that compaction doesn’t happen for every GC, it is run based on some fragmentation heuristics.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-5M6qcguiH8M/TfAYbp8YqMI/AAAAAAAAAVk/Mw9UnXN5ZiI/s1600-h/5%25255B4%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="5" border="0" alt="5" src="http://lh4.ggpht.com/-UK_KrYVuObA/TfAYb-l8U0I/AAAAAAAAAVo/5vnGc9pheeU/5_thumb%25255B2%25255D.png?imgmax=800" width="493" height="185"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Both C and D is moved here to squeeze out the hole for B. At the same time all references to these objects in the system is also update to point to the correct location. &lt;/p&gt; &lt;p&gt;One important thing to note here is that unlike native objects, managed objects can move around in memory due to compaction and hence taking direct references to it (a.k.a memory pointers) is not possible. In case this is ever required, e.g. a managed buffer is passed to say the microphone driver native code to copy recorded audio into, the GC has to be notified that the corresponding managed object cannot be moved during compaction. If the GC runs a compaction and object moves during that microphone PCM data copy, then memory corruption will happen because the object being copied into would’ve moved. To stop that, &lt;a href="http://msdn.microsoft.com/en-us/library/khk3k17t(v=VS.95).aspx"&gt;GCHandle&lt;/a&gt; has to be created to that object with &lt;a href="http://msdn.microsoft.com/en-us/library/83y4ak54(v=VS.95).aspx"&gt;GCHandleType.Pinned&lt;/a&gt; to notify the GC that the corresponding object should never move. &lt;/p&gt; &lt;p&gt;On the WP7 the interfaces to these peripherals and sensors are wrapped by managed interfaces and hence the WP7 developer doesn’t really have to do these things, they are taken care offm under the hood by those managed interfaces.&lt;/p&gt; &lt;h2&gt;The performance issue&lt;/h2&gt; &lt;p&gt;As mentioned before during the entire GC the execution of the application is stopped. So as long as the GC is running the application is frozen. This isn’t a problem in general because the GC runs pretty fast and infrequently. So small latencies of the order of 10-20ms is not really noticeable.&lt;/p&gt; &lt;p&gt;However, with WP7 the capability of the device in terms of CPU and memory drastically increased. Games and large Silverlight applications started coming up which used close to 100mb of memory. As memory increases the number of references those many objects can have also increases exponentially. In the scheme explained above the GC has to traverse each and every object and their reference to mark them and later remove them via sweep. So the GC time also increases drastically and becomes a function of the net workingset of the application. This results in very large pauses in case of large XNA games and SL applications which finally manifests as long startup times (as GC runs during startup) or glitches during the game play/animation.&lt;/p&gt; &lt;h2&gt;Generational Approach&lt;/h2&gt; &lt;p&gt;If we take a look at a &lt;u&gt;simplified &lt;/u&gt;allocation pattern of a typical game (actually other apps are also similar), it looks somewhat like below&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-zcz9c-2TMl0/TfAYb2oxJnI/AAAAAAAAAVs/AXTbzuWFRJc/s1600-h/image%25255B9%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/-aeD9uohVzeU/TfAYcAqcDnI/AAAAAAAAAVw/TiN6oyIrIYI/image_thumb%25255B5%25255D.png?imgmax=800" width="617" height="387"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The game has a large steady state memory which contains much of it’s steady state data (which are not released) and then per-frame it goes on allocating/de-allocating some more data, e.g. for physics, projectiles, frame-data. To collect this memory layout the traditional GC has to walk or traverse the entire 50+ mb of data to locate the garbage in it. However, most of the data it traverses will almost never be garbage and will remain in use.&lt;/p&gt; &lt;p&gt;This application behavior is used for the Generational GC premise&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Most objects die young  &lt;li&gt;If an object survives collection (that is doesn’t die young) it will survive for a very long time &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Using these premise the generational GC tries to segregate the managed heap into older and younger generations objects. The younger generation called &lt;strong&gt;Gen-0&lt;/strong&gt; is collected in each GC (premise 1), this is called the &lt;strong&gt;Ephemeral &lt;/strong&gt;or &lt;strong&gt;Gen0 Collection&lt;/strong&gt;. The older generation is called &lt;strong&gt;Gen-1&lt;/strong&gt;. The GC rarely collects the Gen-1 as the probability of finding garbage in it is low (premise 2).&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh3.ggpht.com/-WjZgQj41NVM/TfAYcbxJVtI/AAAAAAAAAV0/aY1E7mT5VYU/s1600-h/image%25255B13%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-KJd3b76ct5w/TfAYcftZQeI/AAAAAAAAAV4/IqGKS_ZnWg0/image_thumb%25255B7%25255D.png?imgmax=800" width="642" height="133"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;So essentially the GC becomes free of the burden of the net working set of the application. &lt;/p&gt; &lt;p&gt;Most GC will be ephemeral GC and it will only traverse the recently allocated objects, hence the GC latency remains very low. Post collection the surviving objects are promoted to the higher generation. Once a lot of objects are promoted, the higher generation starts becoming full and then a full collection is run (which collects both gen-1 and gen-0). However, due to premise 1, the ephemeral collection finds a lot of garbage in their runs and hence promotes very few objects. This means the growth rate of the higher generation is low and hence full-collection will run very infrequently.&lt;/p&gt; &lt;h2&gt;Ephemeral/Gen-0 collection&lt;/h2&gt; &lt;p&gt;Even in ephemeral collection the GC needs to deterministically find all objects in Gen-0 which are not reachable. This means the following objects needs to survive a Gen-0 collection&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Objects directly reachable from roots  &lt;li&gt;Root –&amp;gt; Gen0 –&amp;gt; Gen-0 objects (indirectly reachable from roots)  &lt;li&gt;Objects referenced from Gen1 to Gen0 &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Now #1 and #2 pose no issues as in the Ephemeral GC, we will anyway scan all roots and Gen-0 objects. However to find objects from Gen1 which are referencing objects in Gen-0, we would have to traverse and look into all Gen1 objects. This will break the very purpose of having segregating the memory into generation. To handle this write-barrier+card-table technique is used. &lt;/p&gt; &lt;p&gt;The runtime maintains a special table called card-table. Each time any references are taken in the managed code e.g. &lt;font face="Courier New"&gt;a.b = c;&lt;/font&gt; the code JITed for this assignment also updates an internal data-structure called CardTable to capture that write. Later during the ephemeral collection, the GC looks into that table to find all the ‘&lt;font face="Courier New"&gt;a&lt;/font&gt;’ which took new references. If that ‘&lt;font face="Courier New"&gt;a&lt;/font&gt;’ is a gen-1 object and ‘&lt;font face="Courier New"&gt;c&lt;/font&gt;’ a gen-0 object then it marks ‘&lt;font face="Courier New"&gt;c&lt;/font&gt;’ recursively (which means all objects reachable from ‘&lt;font face="Courier New"&gt;c’&lt;/font&gt; is also marked). This technique ensures that without examining all the gen-1 objects we can still find all live objects in Gen-0. However, the cost paid is &lt;/p&gt; &lt;ol&gt; &lt;li&gt;Updating object reference is a little bit more costly now  &lt;li&gt;Making old object taking references to new objects increases GC latency (more about these in later posts) &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Putting it all together, the traditional GC would traverse all references shown in the diagram below. However, an ephemeral GC can work without traversing the huge number of Red references.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/-b4j38ppHdjI/TfAYcmJulII/AAAAAAAAAV8/WnsqxI8DvBI/s1600-h/image%25255B21%25255D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/-Z7_B2nLqED8/TfAYc19bHNI/AAAAAAAAAWA/5QPA_gDCnlw/image_thumb%25255B11%25255D.png?imgmax=800" width="644" height="359"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;It scans all the Roots to Gen-0 references (&lt;font color="#00ff40"&gt;green&lt;/font&gt;) directly. It traverses all the Gen1-&amp;gt;Gen0 references (&lt;font color="#f79646"&gt;orange&lt;/font&gt;) via the CardTable data structure.&lt;/p&gt; &lt;h2&gt;Conclusion&lt;/h2&gt; &lt;ol&gt; &lt;li&gt;Generational GC reduces the GC latency by avoiding looking up all objects in the system  &lt;li&gt;Most collections are gen-0 or ephemeral collection and are of low latency this ensures fast startup and low latency in game play  &lt;li&gt;However, based on how many objects are being promoted full GC’s are run sometimes. When they do, they exhibit the same latency as a full GC on the previous WP7 GC &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Given the above most applications will see startup and in-execution perf boost without any modification. E.g today if an application allocates 5 MB of data during startup and GC runs after every MB of allocation then it traverses 15mb (1 + 2 + 3 + 4 + 5). However, with GenGC it might get away with traversing as low as only 5mb.&lt;/p&gt; &lt;p&gt;In addition, especially game developers can optimize their in-gameplay allocations such that during the entire game play there is no full collection and hence only low-latency ephemeral collections happens.&lt;/p&gt; &lt;p&gt;How well the generational scheme works depend on a lot of parameters and has some nuances. In the subsequent posts I will dive into the details of our implementation and some of the design choices we made and what the developers needs to do to get the most value out of it.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-8656817271632112164?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/8656817271632112164/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=8656817271632112164&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/8656817271632112164?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/8656817271632112164?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2011/06/wp7-mango-mark-sweep-collection-and-how.html" title="WP7 Mango: Mark-Sweep collection and how does a Generational GC help" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm6.static.flickr.com/5265/5663301171_692ae168e2_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEIMQHw9fSp7ImA9Wx9XEUQ.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-1115002272354402491</id><published>2011-01-05T08:33:00.001+05:30</published><updated>2011-01-05T08:33:01.265+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-01-05T08:33:01.265+05:30</app:edited><title>WP7: When does GC Consider a Local Variable as Garbage</title><content type="html">&lt;a src="http://www.flickr.com/photos/abhinaba/5003786184/in/photostream/"&gt;&lt;/a&gt;&lt;a href="http://www.flickr.com/photos/abhinaba/5003786184/"&gt;&lt;img style="margin: " src="http://farm5.static.flickr.com/4132/5003786184_6366343eb9.jpg"&gt;&lt;/a&gt;&lt;/a&gt;&amp;nbsp; &lt;p&gt;Consider the following code that I received&lt;/p&gt;&lt;pre class="code"&gt;static void Foo()&lt;br /&gt;{&lt;br /&gt;    TestClass t = new TestClass();&lt;br /&gt;    List&amp;lt;object&amp;gt;l = new List&amp;lt;object&amp;gt;();&lt;br /&gt;    l.Add(t); &lt;font color="#9bbb59"&gt;// Last use of l and t&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;    WeakReference w = new WeakReference(t);&lt;br /&gt;&lt;br /&gt;    GC.Collect();&lt;br /&gt;    GC.WaitForPendingFinalizers();&lt;br /&gt;&lt;br /&gt;    Console.WriteLine("Is Alive {0}", w.IsAlive);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;If this code is is run on the desktop it prints &lt;font face="Courier New"&gt;Is Alive &lt;strong&gt;&lt;u&gt;False&lt;/u&gt;&lt;/strong&gt;&lt;/font&gt;. Very similar to the observation made by a developer in &lt;a title="http://stackoverflow.com/questions/3161119/does-the-net-garbage-collector-perform-predictive-analysis-of-code" href="http://stackoverflow.com/questions/3161119/does-the-net-garbage-collector-perform-predictive-analysis-of-code"&gt;http://stackoverflow.com/questions/3161119/does-the-net-garbage-collector-perform-predictive-analysis-of-code&lt;/a&gt;. This happens because beyond the last usage of &lt;font face="Courier New"&gt;l and t&lt;/font&gt;, the desktop GC considers &lt;font face="Courier New"&gt;l &lt;/font&gt;and &lt;font face="Courier New"&gt;t&lt;/font&gt; to be garbage and collects it. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Even though this seems trivial, it isn’t. During JITing of this method the JITer performs code analysis and ensures that runtime tables are updated to reflect whether at a particular time a given local variable is alive or not (it is not used beyond that point). This needs a bunch of data structures to be maintained (lifetime tables) and also dynamic analysis of code.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;In case of Windows Phone 7 (or other platforms using NETCF) for the same code you’d get &lt;font face="Courier New"&gt;Is Alive &lt;strong&gt;&lt;u&gt;True&lt;/u&gt;&lt;/strong&gt;&lt;/font&gt;. Which means the NETCF GC considers the object to be alive even beyond it’s last usage in the function.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Due to the limited resources available on devices, NETCF does not do these dynamic analysis. So we trade off some runtime performance to ensure faster JITing (and hence application faster startup). All local variables of all functions in the call stacks of the all managed threads in execution during garbage collection is considered live (hence also object roots) and not collect. In NETCF the moment the function &lt;font face="Courier New"&gt;Foo&lt;/font&gt; returns and the stack is unwound the local objects on it including &lt;font face="Courier New"&gt;t&lt;/font&gt; and &lt;font face="Courier New"&gt;l&lt;/font&gt; becomes garbage.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Do note that both of these implementations follow the ECMA specification (ECMA 334 Section 10.9) which states&lt;/p&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;p&gt;“&lt;em&gt;For instance, if a local variable that is in scope is the only existing reference to an object, but that local variable is never referred to in any possible continuation of execution from the current execution point in the procedure, an implementation might (but is not required to) treat the object as no longer in use&lt;/em&gt;.”&lt;/p&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;p&gt;Hence even though on the desktop CLR it is not important to set variables to null, it is sometimes required to do so on WP7. In case &lt;font face="Courier New"&gt;t&lt;/font&gt; and &lt;font face="Courier New"&gt;l&lt;/font&gt; was set to null GC would’ve collected them. So the guidance for WP7 is&lt;/p&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;In most cases setting local variables to null is not required. Especially if the function returns fairly soon &lt;br /&gt;&lt;li&gt;If you have locals that hold onto very large data structures and that function will remain executing for a long time then set those variables to null when you are done using them (e.g. in between the last usage of a variable in a large function and calls to a bunch of web-services in the same function which will take a long time to return).&lt;!--EndFragment--&gt; &lt;br /&gt;&lt;li&gt;Use dispose patterns where required. It’s important on devices to free up limited resources as soon as possible.&lt;/li&gt;&lt;/ol&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-1115002272354402491?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/1115002272354402491/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=1115002272354402491&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/1115002272354402491?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/1115002272354402491?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2011/01/wp7-when-does-gc-consider-local.html" title="WP7: When does GC Consider a Local Variable as Garbage" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm5.static.flickr.com/4132/5003786184_6366343eb9_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DE8BSX06cSp7ImA9Wx5TFEk.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-6269086762778638227</id><published>2010-07-30T05:10:00.001+05:30</published><updated>2010-07-30T05:10:58.319+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-07-30T05:10:58.319+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Garbage Collection" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><title>Windows Phone 7 App Development: When does the GC run</title><content type="html">&lt;img alt="Cub" src="http://farm5.static.flickr.com/4113/4831888231_76975c7157.jpg"&gt;  &lt;p&gt;Many moons ago I made a post on &lt;a href="http://blogs.msdn.com/b/abhinaba/archive/2008/04/29/when-does-the-net-compact-framework-garbage-collector-run.aspx"&gt;When does the .NET Compact Framework Garbage Collector run&lt;/a&gt;. Given that a lot of things have changed since then, it’s time to make another post about the same thing.&lt;/p&gt; &lt;p&gt;For the developers coming to Windows Phone 7 (WP7) from the Windows desktop let me first clarify that the runtime (CLR) that is running on the WP7 is not the same as the one running on the desktop. The WP7 runtime is known as .NET Compact Framework (NETCF) and it works differently than the “desktop CLR”. For 90% of cases this is irrelevant as the WP7 developer targets the XNA or Silverlight programming model and hence what is running underneath is really not important. E.g when you drive you really do not care about the engine. This post is for the other 5% where folks do run into issues (smoke coming out of the car). &lt;/p&gt; &lt;p&gt;Moreover do note that when the GC is run is really an implementation detail that is subject to change.&lt;/p&gt; &lt;p&gt;Now that we have all the disclaimers behind us lets get down to the list.&lt;/p&gt; &lt;p&gt;The Garbage Collector is run in the following situations&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;After some significant allocation: &lt;br&gt;&lt;/strong&gt;When an application tries to allocate managed memory the allocator first checks a counter that indicates the number of bytes of managed data allocated since the last GC. If this counter crosses a threshold (which is changeable and set to 1MB &lt;u&gt;currently&lt;/u&gt;) then GC is fired (and the counter is obviously reset). &lt;br&gt;The basic idea is that there has been significant allocation since the last GC and hence do it again. &lt;br&gt; &lt;li&gt;&lt;strong&gt;Resource allocation failure &lt;br&gt;&lt;/strong&gt;If some internal native allocation fails, like loadlibrary fails or JIT buffer allocation fails due to out-of-memory condition then GC is started to free up some memory and the allocation is re-attempted (only 1 re-attempt) &lt;br&gt; &lt;li&gt;&lt;strong&gt;User code can trigger GC&lt;/strong&gt; &lt;br&gt;Using the managed API System.GC.Collect(), user code can force a GC &lt;br&gt; &lt;li&gt;&lt;strong&gt;Sharing server initiated &lt;br&gt;&lt;/strong&gt;One of the new features in the WP7 CLR is the sharing server (see my post &lt;a title="http://blogs.msdn.com/b/abhinaba/archive/2010/04/28/we-believe-in-sharing.aspx" href="http://blogs.msdn.com/b/abhinaba/archive/2010/04/28/we-believe-in-sharing.aspx"&gt;http://blogs.msdn.com/b/abhinaba/archive/2010/04/28/we-believe-in-sharing.aspx&lt;/a&gt; for details). In WP7 there is a central server coordinating all the managed processes. If this sharing server is notified of low memory condition, it starts GC in all the managed processes in the system. &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;The GC is &lt;strong&gt;&lt;u&gt;NOT&lt;/u&gt;&lt;/strong&gt; run in the following cases (I am explicitly calling these out because in various conferences and interactions I’ve heard folks thinking it might be)&lt;/p&gt; &lt;ol&gt; &lt;li&gt;GC is not run on some timer. So if a process is not allocating any memory and there is no low-memory situation then GC will never be fired irrespective of how long the application is running  &lt;li&gt;The phone is never woken up by the CLR to run GC. GC is always in response to an active request OR allocation failure OR low memory notification.  &lt;li&gt;In the same lines there is no GC thread or background GC on WP7 &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;For folks migrating from NETCF 3.5 the list below gives you the changes &lt;/p&gt; &lt;ol&gt; &lt;li&gt;WinForm Application going to background used to fire GC. On WP7 this is no longer true  &lt;li&gt;Sharing server based changes are obviously new  &lt;li&gt;The GC quantum cannot be changed by user &lt;/li&gt;&lt;/ol&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-6269086762778638227?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/6269086762778638227/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=6269086762778638227&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/6269086762778638227?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/6269086762778638227?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2010/07/windows-phone-7-app-development-when.html" title="Windows Phone 7 App Development: When does the GC run" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm5.static.flickr.com/4113/4831888231_76975c7157_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEEFRHY5fyp7ImA9WxFQF08.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-1779637218192116551</id><published>2010-05-13T09:20:00.001+05:30</published><updated>2010-05-13T09:20:15.827+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-05-13T09:20:15.827+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><title>Inside the Windows Phone Emulator</title><content type="html">&lt;a title="US by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4564464780/"&gt;&lt;img alt="US" src="http://farm4.static.flickr.com/3652/4564464780_7e1e280f29.jpg" width="500" height="405"&gt;&lt;/a&gt;  &lt;p&gt;Learn from the dev lead and PM of Windows Phone 7 Emulator on how it works and delivers the awesome performance.&lt;/p&gt; &lt;p&gt;Some key points&lt;/p&gt; &lt;ol&gt; &lt;li&gt;The emulator is essentially a x86 based Virtual Machine running full image of Windows Phone 7 OS  &lt;li&gt;It emulates various peripherals (e.g. audio, networking), the list hopefully will grow in the future  &lt;li&gt;Supports multi-touch if your host PC has a touch screen  &lt;li&gt;It uses the GPU on the host PC to accelerate the graphics  &lt;li&gt;&lt;strong&gt;Shameless plug&lt;/strong&gt;: One of the reason it’s possible to emulate x86 and still have managed apps running as-is, is because the runtime (.NET Compact Framework) supports both x86 and ARM seamlessly (provides JITer for both architectures and runs the same managed code on both seamlessly) &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="512" height="384"&gt; &lt;param name="source" value="http://channel9.msdn.com/App_Themes/default/VideoPlayer10_01_18.xap" /&gt; &lt;param name="initParams" value="deferredLoad=true,duration=0,m=http://ecn.channel9.msdn.com/o9/ch9/3/1/9/7/4/5/WPEmulatorDeepDive_ch9.wmv,autostart=false,autohide=true,showembed=true, thumbnail=http://ecn.channel9.msdn.com/o9/ch9/3/1/9/7/4/5/WPEmulatorDeepDive_512_ch9.png, postid=547913" /&gt; &lt;param name="background" value="#00FFFFFF" /&gt; &lt;a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"&gt; &lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /&gt; &lt;/a&gt; &lt;/object&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-1779637218192116551?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/1779637218192116551/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=1779637218192116551&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/1779637218192116551?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/1779637218192116551?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2010/05/inside-windows-phone-emulator.html" title="Inside the Windows Phone Emulator" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm4.static.flickr.com/3652/4564464780_7e1e280f29_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DUUNQ3w6fip7ImA9WxFRFEo.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-2059593444023309814</id><published>2010-04-28T23:24:00.001+05:30</published><updated>2010-04-28T23:24:52.216+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-28T23:24:52.216+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Fun" /><category scheme="http://www.blogger.com/atom/ns#" term="Everything Else" /><title>Working in the United States</title><content type="html">&lt;a title="Eucalyptus trees-  Trek in the hills by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4343339210/"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" alt="Eucalyptus trees-  Trek in the hills" src="http://farm3.static.flickr.com/2772/4343339210_3990938243.jpg" width="375" height="500"&gt;&lt;/a&gt;  &lt;p&gt;I am sure everyone has read about the “you cannot possibly pronounce or spell” volcano in Iceland throwing up in the air and screwing up the entire flight system of this planet. While most people were reading about it from the comfort of their home I was doing the same while waiting in airports with a 5 year old tagged along. Anyways, 48 hours and a switch in the direction of flights got me to some countries I didn’t really plan to visit and over the Pacific to land in Seattle.&lt;/p&gt; &lt;p&gt;Going forward I will be working out of the Microsoft Redmond offices, doing pretty much the same stuff I was doing before (working on the .NET Compact Framework runtime). &lt;/p&gt; &lt;p&gt;Right now I am settling down with my family and my daughter is excited to see snow for the first time (she got lucky as there was a small snowfall on Saturday in Snoqualmie pass). The changes we need to adjust to is humongous, we left Hyderabad when it was 43° Celsius and now it’s 6° Celsius in Redmond. Oh sorry I should’ve said it was 110°F and now it’s&amp;nbsp; 43°F in Redmond.&lt;/p&gt; &lt;p&gt;Wish me luck and hopefully finally I will be able to attend some &lt;a href="http://www.nerddinner.com/"&gt;nerddinners&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-2059593444023309814?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/2059593444023309814/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=2059593444023309814&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/2059593444023309814?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/2059593444023309814?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2010/04/working-in-united-states.html" title="Working in the United States" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2772/4343339210_3990938243_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEIGQX88eCp7ImA9WxFRFEo.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-7780028537153825897</id><published>2010-04-28T23:12:00.000+05:30</published><updated>2010-04-28T23:12:00.170+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-04-28T23:12:00.170+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Coding / .NET" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><category scheme="http://www.blogger.com/atom/ns#" term="Software" /><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight" /><title>We Believe in Sharing</title><content type="html">&lt;a title="Good Morning by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4342599819/"&gt;&lt;img alt="Good Morning" src="http://farm5.static.flickr.com/4046/4342599819_a020deb803.jpg" width="500" height="247"&gt;&lt;/a&gt;  &lt;p&gt;In Building NETCF for Windows Phone 7 series we put in couple of features to enhance startup performance and ensure that the working set remains small. One of these features added is code/data sharing.&lt;/p&gt; &lt;p&gt;Native applications have inherent sharing where multiple processes can share the same executable code. However, in case of managed code running on NETCF 3.5 even when multiple applications use the same assembly, the managed code in them are JITed in context of each process separately. This results in suboptimal resource utilization because of the following&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Repeated JITing of the same code  &lt;li&gt;Memory overhead of having identical copies of the same JITed code for every process running them. The execution engine also maintains records of the various types loaded and even though two (or more) processes may be loading the same types from the same assemblies; per process copies are maintained for them. &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Together the overhead can be significant.&lt;/p&gt; &lt;p&gt;In the latest version of the runtime shipping with Windows Phone 7 (.NET Compact Framework 3.7) we added a feature to share both the JITed code and these type information across multiple managed processes.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_DLceQ4wfZNI/S9hsRjy-8cI/AAAAAAAAAOE/ZmXAyzMNjH8/s1600-h/image%5B3%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_DLceQ4wfZNI/S9hsSA0UxjI/AAAAAAAAAOI/SlJh3LH6NcA/image_thumb%5B1%5D.png?imgmax=800" width="728" height="521"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;The runtime essentially uses a client server architecture. We added a new kernel mode server &lt;br&gt;which is responsible of maintaining a system wide shared heap. The server on receiving requests &lt;br&gt;from the various client processes (each managed app is a client) JITs code and type information &lt;br&gt;into this shared heap. The shared heap is accessed Read-only from all the client apps and &lt;br&gt;Read/write from the server.&lt;/p&gt; &lt;p&gt;When a process requests for the same type to be loaded or code to be JITed it just re-uses the already loaded type info or JITed code from the shared heap. &lt;br&gt;What is shared&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Various Execution engine data-structures like loader type-information  &lt;li&gt;JITed code from a predefined list of platform assemblies (user code is not shared).&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Do note that &lt;strong&gt;user code is not shared and neither is all platform code&lt;/strong&gt;. Sharing arbitrarily would actually increase cost if they ultimately didn’t get reused in a lot of applications. The list of assemblies/data shared was carefully chosen and tuned to ensure only those are shared that provided the maximum performance benefit.&lt;/p&gt; &lt;p&gt;Sharing provides the following advantages&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Warm startup time is significantly reduced. When a new application is coming up a large &lt;br&gt;percentage of the initial code and type-info is already found on the shared heap and hence &lt;br&gt;there is significant perf boost. The exact number depends on the applications but it’s common &lt;br&gt;to get around 30% gains  &lt;li&gt;Significant reduction in net working set as a lot of commonly used platform assembly JITed code is re-used  &lt;li&gt;Obviously there are other goodness like less JITing means less processing on the device &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Like user code the system is also capable of pitching the shared code when there is a low memory situation on the device.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-7780028537153825897?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/7780028537153825897/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=7780028537153825897&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/7780028537153825897?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/7780028537153825897?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2010/04/we-believe-in-sharing.html" title="We Believe in Sharing" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm5.static.flickr.com/4046/4342599819_a020deb803_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D0QMRn0zcCp7ImA9WxBbGEg.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-3642467942881233817</id><published>2010-03-18T01:19:00.001+05:30</published><updated>2010-03-18T01:19:47.388+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-03-18T01:19:47.388+05:30</app:edited><title>Comparing Windows Phone with .NET Compact Framework 3.5</title><content type="html">&lt;a title="Bidar - Fort by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279002293/"&gt;&lt;img alt="Bidar - Fort" src="http://farm5.static.flickr.com/4056/4279002293_b9482441d1.jpg" width="375" height="500"&gt;&lt;/a&gt;  &lt;p&gt;In the comments of my previous post &lt;a href="http://blogs.msdn.com/abhinaba/archive/2010/03/13/windows-phone-7-series-programming-model.aspx"&gt;Windows Phone 7 Series Programming Model&lt;/a&gt; and elsewhere (e.g. twitter, WP7 forum) there seems to be a lot of confusion around how NETCF 3.5 compares against the new WP7 programming model powered by NETCF 3.7. People are asking why some API got removed from 3.5, or is 3.7 a subset of NETCF 3.5 as they are not seeing some familiar 3.5 APIs. &lt;/p&gt; &lt;p&gt;First I’d urge you to go visit the &lt;a href="http://blogs.msdn.com/abhinaba/archive/2010/03/13/windows-phone-7-series-programming-model.aspx"&gt;Windows Phone 7 Series Programming Model&lt;/a&gt; to see what it offers.&lt;/p&gt; &lt;p&gt;Essentially NETCF 3.5 can be broken down to &lt;/p&gt; &lt;ol&gt; &lt;li&gt;NETCF 3.5 runtime (the Execution Engine)  &lt;li&gt;NETCF 3.5 BCL  &lt;li&gt;NETCF 3.5 UI programming model (WinForm based) &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Now each of this has been updated (in order) as follows&lt;/p&gt; &lt;ol&gt; &lt;li&gt;NETCF 3.7 runtime (hugely updated Execution Engine)  &lt;li&gt;NETCF 3.7 BCL (essentially offering the Silverlight 3 BCL Apis with a small delta)  &lt;li&gt;The UI model has been replaced and offers two options  &lt;ol&gt; &lt;li&gt;Silverlight 3 UI + Windows Phone device specific features (e.g. accelerometer , location service)  &lt;li&gt;XNA features with Windows Phone device specific features (e.g. accelerometer , location service) &lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;So the runtime is hugely updated (and hopefully you’d feel the improvements, especially in performance). &lt;/p&gt; &lt;p&gt;For #2 and #3 the level of difference is same in magnitude as you compare WinForm with Silverlight on desktop. They are simply two different programming models.&lt;/p&gt; &lt;p&gt;In case you hit a 3.5 API&amp;nbsp; that’s missing then it’s either because it’s (a) WinForm based API that got totally replaced, or (b) a BCL API that the Silverlight profile doesn’t support. The workaround is to search for how to do the same thing in Silverlight (e.g. &lt;a href="http://forums.silverlight.net/forums/t/11702.aspx"&gt;use XDocument instead of XmlDocument&lt;/a&gt;). In some cases you’d get into situations where there is no direct alternative. E.g. there is no P/Invoke and if your code say P/Invoked to get data from a bar-code scanner you cannot do so now. &lt;/p&gt; &lt;p&gt;Also keep in mind that the bits available right now is just early preview bits and subject to a lot of change. The whole purpose of having CTPs is to hear our customers and ensure we use the remaining time before release in fixing issues that helps our customers the most. Hopefully some of the gaps will get closed before the final release.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-3642467942881233817?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/3642467942881233817/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=3642467942881233817&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/3642467942881233817?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/3642467942881233817?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2010/03/comparing-windows-phone-with-net.html" title="Comparing Windows Phone with .NET Compact Framework 3.5" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm5.static.flickr.com/4056/4279002293_b9482441d1_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D0UMQng9eip7ImA9WxBbGEg.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-2652937505435543058</id><published>2010-03-18T01:18:00.001+05:30</published><updated>2010-03-18T01:18:03.662+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-03-18T01:18:03.662+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Coding / .NET" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight" /><title>Silverlight on Nokia S60 platform</title><content type="html">&lt;a title="Bidar - Fort by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279002841/"&gt;&lt;img alt="Bidar - Fort" src="http://farm3.static.flickr.com/2723/4279002841_e2d6aba3c4.jpg" width="500" height="375"&gt;&lt;/a&gt;  &lt;p&gt;Today at &lt;a href="http://live.visitmix.com/"&gt;MIX 2010&lt;/a&gt; we announced &lt;a href="http://www.microsoft.com/silverlight/"&gt;Silverlight&lt;/a&gt; beta for &lt;a href="http://en.wikipedia.org/wiki/Nokia_S60"&gt;Nokia S60&lt;/a&gt; phones. Go download the beta from &lt;a href="http://silverlight.net/getstarted/devices/symbian/"&gt;http://silverlight.net/getstarted/devices/symbian/&lt;/a&gt;.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Currently the supported platform is S60 5th Edition phones and in particular the &lt;a href="http://www.forum.nokia.com/devices/5800_XpressMusic/"&gt;5800 XpressMusic&lt;/a&gt;, &lt;a href="http://www.forum.nokia.com/devices/N97/"&gt;N97&lt;/a&gt; and &lt;a href="http://www.forum.nokia.com/devices/N97_mini/"&gt;N97 mini&lt;/a&gt;. It works in-browser and only in the Nokia default web-kit based browser. &lt;/p&gt; &lt;p&gt;Silverlight on S60 uses .NET Compact Framework (NETCF) underneath it. I work in the dev team for the Execution Engine of NETCF and I was involved at the very beginning with getting NETCF to work on the S60 platform.&lt;/p&gt; &lt;p&gt;NETCF is extremely portable (more about that in later posts) and hence we didn’t have a lot of trouble getting it onto S60. We abstract away the platform by coding against a generic platform abstraction layer (PAL), but even then we had some challenges. Getting .NET platform on a non-Windows OS is challenging because so much of our code relies on Windows like functionality (semantics) which might not be available directly on other platforms. &lt;/p&gt; &lt;p&gt;As I was digging through emails I found the following screenshot that I had sent out to the team when I just got NETCF to work on the S60 Emulator…&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/abhinaba/WindowsLiveWriter/SilverlightonNokiaS60platform_3AB/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/abhinaba/WindowsLiveWriter/SilverlightonNokiaS60platform_3AB/image_thumb.png" width="779" height="630"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;As you can see the first code to run was a console application and it was not Hello World :). We have come a long way since then as evident from the touch based casual game running on the N97 shown below&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_DLceQ4wfZNI/S6Ex4P9P8MI/AAAAAAAAANk/FOi8lxmzXT8/s1600-h/image15.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_DLceQ4wfZNI/S6Ex8V64SOI/AAAAAAAAANo/OcEkuPsVgPc/image_thumb9.png?imgmax=800" width="304" height="513"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-2652937505435543058?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/2652937505435543058/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=2652937505435543058&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/2652937505435543058?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/2652937505435543058?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2010/03/silverlight-on-nokia-s60-platform.html" title="Silverlight on Nokia S60 platform" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2723/4279002841_e2d6aba3c4_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D0YARHo6fCp7ImA9WxBbGEg.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-7919392186953472147</id><published>2010-03-18T01:15:00.001+05:30</published><updated>2010-03-18T01:15:45.414+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-03-18T01:15:45.414+05:30</app:edited><title>Windows Phone 7 Series Programming Model</title><content type="html">&lt;p&gt;&lt;a title="Bidar - Barid Shahi tombs by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279757408/" mce_href="http://www.flickr.com/photos/abhinaba/4279757408/"&gt;&lt;img alt="Bidar - Barid Shahi tombs" src="http://farm5.static.flickr.com/4031/4279757408_2703982772.jpg" width="500" height="375" mce_src="http://farm5.static.flickr.com/4031/4279757408_2703982772.jpg"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Just sometime back I posted on the &lt;font color="#ff0000"&gt;&lt;a href="http://blogs.msdn.com/abhinaba/archive/2010/03/13/mix-2010-announcements.aspx" mce_href="/abhinaba/archive/2010/03/13/mix-2010-announcements.aspx"&gt;MIX 2010 announcements&lt;/a&gt;&lt;/font&gt;. One of the major aspects of the announcement was &lt;/p&gt; &lt;p&gt;“The application model supported on Windows Phone 7 series will be managed only and will leverage &lt;a href="http://www.microsoft.com/silverlight/" mce_href="http://www.microsoft.com/silverlight/"&gt;Silverlight&lt;/a&gt;, &lt;a href="http://www.xna.com/" mce_href="http://www.xna.com/"&gt;XNA&lt;/a&gt; and the .NET Framework”&lt;/p&gt; &lt;p&gt;That’s a mouthful and includes 3 framework names in once sentence :). This was already &lt;a href="http://blogs.msdn.com/ckindel/archive/2010/03/04/different-means-better-with-the-new-windows-phone-developer-experience.aspx" mce_href="http://blogs.msdn.com/ckindel/archive/2010/03/04/different-means-better-with-the-new-windows-phone-developer-experience.aspx"&gt;disclosed&lt;/a&gt; and has resulted in some flutter over the web and twitter. Let me try to explain how these 3 interplays in the application model with the following diagram&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/abhinaba/WindowsLiveWriter/WindowsPhone7SeriesProgrammingModel_11AC8/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/abhinaba/WindowsLiveWriter/WindowsPhone7SeriesProgrammingModel_11AC8/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/abhinaba/WindowsLiveWriter/WindowsPhone7SeriesProgrammingModel_11AC8/image_thumb_2.png" width="804" height="590" mce_src="http://blogs.msdn.com/blogfiles/abhinaba/WindowsLiveWriter/WindowsPhone7SeriesProgrammingModel_11AC8/image_thumb_2.png"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;strong&gt;Managed only&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;First of all the application model allows users to write only managed code&lt;strong&gt; &lt;/strong&gt;(to repeat native code is not allowed). That means they do not have direct access to any native APIs and cannot use platform-invoke to call into native user or system code. So all resources including phone capabilities have to be accessed using the various managed APIs provided.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Two Flavors of applications (XNA and Silverlight)&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;There are 2 variants or flavors of applications users can write, XNA Games and Silverlight applications. Obviously the former is for writing games and the later is for your typical phone applications (nothing stops you from writing a Silverlight animation based game though). So you cannot mix-match SL and XNA UI in the same application.&lt;/p&gt; &lt;p&gt;However, do note that the traditional NETCF development using WinForm based UI is not supported.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Common Services available to both&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;That said, beyond the UI rendering and controls there is the common services which both SL and XNA applications can use. This includes all the phone capabilities like microphone, location, accelerometer, sound, media, networking, etc... &lt;strong&gt;Some of these features come from SL and others from XNA&lt;/strong&gt; but land up in the common pool usable by either types of applications.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Core Runtime is .NET Compact Framework 3.7&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The core runtime for both SL and XNA applications&lt;strong&gt; &lt;/strong&gt;is .NET Compact Framework (henceforth called NETCF). This is the team I work for.&amp;nbsp; .NETCF is a highly portable and compact (as in smaller size and footprint) implementation of the .NET specification. It is designed to run on resource constrained devices and on disparate HW and SW configurations.I will have a post later on the detailed architecture or .NETCF.&lt;/p&gt; &lt;p&gt;Over the last two years a lot of work has gone into .NETCF to scale it in terms of features, performance and stress to meet the requirements of Windows Phone and other newer platforms on which it is being targeted. We also added a lot of features which I hope you will enjoy. Some of the features is just to reach parity with the desktop CLR and others are device specific and not available on the desktop.&lt;/p&gt; &lt;p&gt;Over this blog in the course of the coming months I’ll try to share with you what all we did to reach here. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-7919392186953472147?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/7919392186953472147/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=7919392186953472147&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/7919392186953472147?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/7919392186953472147?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2010/03/windows-phone-7-series-programming.html" title="Windows Phone 7 Series Programming Model" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm5.static.flickr.com/4031/4279757408_2703982772_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;Dk4CQ3kzcCp7ImA9WxBbGEg.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-9031101217805717989</id><published>2010-03-18T01:12:00.001+05:30</published><updated>2010-03-18T01:12:42.788+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-03-18T01:12:42.788+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Windows Phone" /><category scheme="http://www.blogger.com/atom/ns#" term="Coding / .NET" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><title>MIX 2010 Announcements</title><content type="html">&lt;a title="Bidar Trip - Mohamad Gawan Madrasa by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279733136/"&gt;&lt;img alt="Bidar Trip - Mohamad Gawan Madrasa" src="http://farm3.static.flickr.com/2759/4279733136_75c4a5df85.jpg" width="500" height="323"&gt;&lt;/a&gt;  &lt;p&gt;Today is a very big day for me and my team. The stuff we have been working on is finally went live on stage &lt;a href="http://live.visitmix.com/"&gt;MIX 2010&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Windows Phone 7 is easily the most dramatic re-entry/reset Microsoft has undertaken in any field it’s in. We &lt;a href="http://www.microsoft.com/presspass/presskits/windowsphone/default.aspx"&gt;announced&lt;/a&gt; the phone in MWC and the reception it got was phenomenal. However, in the new connected devices world, the application platform+market story is as or more important than the device itself. Today at MIX we just disclosed details of that.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;The application model supported on Windows Phone 7 series will be &lt;strong&gt;managed only and will leverage &lt;/strong&gt;&lt;a href="http://www.microsoft.com/silverlight/"&gt;&lt;strong&gt;Silverlight&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;, &lt;/strong&gt;&lt;a href="http://www.xna.com/"&gt;&lt;strong&gt;XNA&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; and the .NET Compact Framework&lt;/strong&gt;. So basically you can reuse your C#/.NET and Silverlight skills to build amazing experience on the phone. I will get into details of this in the coming posts  &lt;li&gt;Microsoft just announced &lt;strong&gt;free Windows Phone Developer Tools &lt;/strong&gt;(preview bits available for download head over to &lt;a title="http://developer.windowsphone.com/" href="http://developer.windowsphone.com/"&gt;http://developer.windowsphone.com/&lt;/a&gt; )  &lt;ol&gt; &lt;li&gt;This builds on the amazing development experience brought in by the Visual Studio 2010 shell.  &lt;li&gt;You can either get a standalone Visual Studio 2010 Express for Windows Phone Or an addin for your previously installed VS 2010  &lt;li&gt;Windows Phone 7 series emulator (yes you &lt;strong&gt;do not even need a device to develop for Windows Phone&lt;/strong&gt;) &lt;/li&gt;&lt;/ol&gt; &lt;li&gt;A version of &lt;a href="http://www.microsoft.com/expression/products/Blend_Overview.aspx"&gt;Expression Blend&lt;/a&gt; is also demonstrated for the Windows Phone (a free version will be available for download in the coming months)  &lt;li&gt;A new Windows Phone Marketplace is being put into place  &lt;ol&gt; &lt;li&gt;Developers can earn 70% revenue from the applications they sell of the marketplace  &lt;li&gt;The registration to the market place is not free but it’ll be free for the &lt;a href="https://www.dreamspark.com/"&gt;DreamSpark&lt;/a&gt; program for students &lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Our team was involved with building the IDE, the emulator and the core .NET runtime that powers the applications. So watch out and in the coming posts I’ll deep dive into these areas. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-9031101217805717989?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/9031101217805717989/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=9031101217805717989&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/9031101217805717989?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/9031101217805717989?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2010/03/mix-2010-announcements.html" title="MIX 2010 Announcements" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2759/4279733136_75c4a5df85_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0UMR3k8eSp7ImA9WxBQF04.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-1018585733578085004</id><published>2010-01-17T17:57:00.000+05:30</published><updated>2010-01-17T17:58:06.771+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-17T17:58:06.771+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Amazing India" /><category scheme="http://www.blogger.com/atom/ns#" term="travel" /><category scheme="http://www.blogger.com/atom/ns#" term="Everything Else" /><title>Bidar road trip from Hyderabad</title><content type="html">&lt;p&gt;Just went for a short day trip to Bidar from Hyderabad on &lt;strong&gt;Jan 16, 2010&lt;/strong&gt;. This post is to document the whole plan and quick tips&amp;nbsp; Since we travelled with GPS and Google maps have excellent coverage of the area we didn’t face any issues.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;The way to Bidar&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The route maps on Google &lt;a href="http://maps.google.com/maps/ms?ie=UTF8&amp;amp;hl=en&amp;amp;msa=0&amp;amp;msid=108719718837121935502.00047d57bf3a664279b6d&amp;amp;z=10"&gt;here&lt;/a&gt;. The total distance came out to be&lt;a title="Bidar Trip - On the way by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279723296/"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" alt="Bidar Trip - On the way" align="right" src="http://farm5.static.flickr.com/4005/4279723296_faf6376364_m.jpg" width="240" height="191"&gt;&lt;/a&gt; around 115kms from Miyapur. The route is pretty straight forward. Get onto NH9 which goes from Hyderabad to Pune and onward to Mumbai. Drive around 85km and then take a right onto SH4 and drive around 26 km to reach Bidar (which is in Karnataka). The right turn is well marked out and clearly points that it goes to Bidar. &lt;/p&gt; &lt;p&gt;We started around 7:00 a.m from Hyderabad and even though we expected around 2 hours of driving it turned out to be 3 hours as we took a pit-stop in the Haritha Restaurant (&lt;a href="http://www.aptdc.in/"&gt;APTDC&lt;/a&gt;) for breakfast. The restaurant came around 60-65 kms from Hyderabad. The choice of food was limited but the Poori and Idli we had was steaming hot and sumptuous. The bathrooms were clean as well :). The stop is highly recommended.&lt;/p&gt;&lt;a title="Bidar Trip - On the way by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4278979407/"&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" alt="Bidar Trip - On the way" align="left" src="http://farm5.static.flickr.com/4052/4278979407_f2088da2a4_m.jpg" width="240" height="150"&gt;&lt;/a&gt;The road was excellent all the way and traffic was sparse, I could drive easily at 100kmph. Just before reaching Bidar there is a reserve forest and when we were driving through a tiger leapt in front of our car. Ok I was kidding the forest is there and my daughter was trying to see a tiger :)&lt;br&gt; &lt;p&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;In Bidar&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;We took the following route plan inside Bidar&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_DLceQ4wfZNI/S1MCR6ieLWI/AAAAAAAAAMU/sE08HHpo_eQ/s1600-h/image%5B3%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_DLceQ4wfZNI/S1MCTKhrJGI/AAAAAAAAAMY/3TvE59fXxhI/image_thumb%5B1%5D.png?imgmax=800" width="701" height="598"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&lt;a title="Bidar - Bidri by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279023883/"&gt;&lt;img style="margin: 10px 0px 10px 10px; display: inline" alt="Bidar - Bidri" align="right" src="http://farm5.static.flickr.com/4063/4279023883_9ce9fe8a6a_m.jpg" width="240" height="180"&gt;&lt;/a&gt;Just after entering Bidar (A) you’d see an old Fort gate on the right, get into it and you’ve reached the old city. After that you just need continue on the straight road. The un-mistakable clock tower (chaubara) would be infront out you.&lt;/p&gt; &lt;p&gt;&lt;a title="Bidar Trip - Mohamad Gawan Madrasa by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279731144/"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a title="Bidar Trip - Mohamad Gawan Madrasa by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279731144/"&gt;&lt;img style="margin: 10px 10px 10px 0px; display: inline" alt="Bidar Trip - Mohamad Gawan Madrasa" align="left" src="http://farm5.static.flickr.com/4009/4279731144_b0ca6689d5_m.jpg" width="240" height="136"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Our first stop was the remains of the ancient theological college (B), Mohamad Gawan Madrasa. Built in 1472 by Gawan, a Persian exile and scholar of the Bahmani court, this was one of the greatest centers of Islamic learning of its time, attracting students from all over. We got some nice shots of the place and the beautiful green parrots hovering around added to the color.&lt;/p&gt;&lt;a title="Bidar - Fort by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279737866/"&gt;&lt;img style="margin: 10px 0px 10px 10px; display: inline" alt="Bidar - Fort" align="right" src="http://farm5.static.flickr.com/4009/4279737866_20d33e8c37_m.jpg" width="240" height="180"&gt;&lt;/a&gt;  &lt;p&gt;From this we drove another km to the Bidar fort (C), which comes straight ahead. After getting through another set of fort gates we got into the fort.&lt;/p&gt; &lt;p&gt;Do note that the whole idea of fort gates is to make entry difficult and not allow you to see what is ahead, so drive carefully and honk (there is a sign that proclaims horn-mandatory).&lt;/p&gt; &lt;p&gt;Inside the fort we first went to the museum and then asked the folks their to show us around the fort. The fort is kept under lock-key to prevent people from scribbling pappu-loves-pinki on the walls and you need to explicitly ask to be shown around (and tip them at the end). We were shown around the various Mahals, especially the Rangeen Mahal took our breadth away. The museum also has some interesting pieces like locks which are bigger than my door and huge guns which could be carried only by people who anyway didn’t need them.&lt;/p&gt; &lt;p&gt;&lt;a title="Bidar Trip - Mohamad Gawan Madrasa by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279731144/"&gt;&lt;/a&gt;Just outside the museum is the canteen where we grabbed some food and coffee. The whole area around Bidar cultivates sugarcane, and if you are not explicit about it they’d put all of that in your cup of coffee. Energized with all that sucrose we ventured out to the back of the museum to see the diwan-e-aam and diwan-e-khaas.&lt;/p&gt; &lt;p&gt;After that we drove down to the Barid Shahi tombs (D). It has a nice little park and our daughter enjoyed the welcome break from seeing old buildings and enjoyed the slides and slings.&lt;/p&gt; &lt;p&gt;&lt;a title="Bidar - Gurudwara by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279814928/"&gt;&lt;img style="margin: 10px 10px 10px 0px; display: inline" alt="Bidar - Gurudwara" align="left" src="http://farm5.static.flickr.com/4025/4279814928_309cf4f5da_m.jpg" width="240" height="180"&gt;&lt;/a&gt;Our last stop was the &lt;a href="http://www.gnjbidar.com/home.html"&gt;Gurudwara Nanak Jhira Saheb&lt;/a&gt; (E). Finding the was easy as there is a gate on the SH4 from where you need to get into the road that leads to the Gurudwara. Do remember to carry shawls for women and handkerchief for men to cover the hair which is mandatory to enter the Gurudwara. In case you forget you can always get them at the Gurudwara but putting cloth which hundreds have used before might be a bit yucky :).&lt;/p&gt;We paid Rs10 to get some very tasty halwa which was loaded with Ghee. The Gurudwara had clean pay-n-use loo which helped :)&amp;nbsp; &lt;p&gt;&lt;a title="Bidar Trip - Mohamad Gawan Madrasa by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279731144/"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a title="Bidar Trip - Mohamad Gawan Madrasa by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4279731144/"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;We asked the Sardarji security guard for some pointers for good food and we pointed to a fantastic restaurant. It’s called Rohit Restaurant and is on the road that leads to the Gurudwara from SH4 and is just beside the police chowki. It’s Punjabi cuisine, vegetarian and is clean and the food proved to be excellent (their naan/daal-fry can hands down beat any 5-star restaurant). Highly recommended. &lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_DLceQ4wfZNI/S1MCUnhKxbI/AAAAAAAAAMg/C39cHgKBHuw/s1600-h/image%5B9%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://lh4.ggpht.com/_DLceQ4wfZNI/S1MCVdLXS8I/AAAAAAAAAMk/gNDAveSsJdY/image_thumb%5B5%5D.png?imgmax=800" width="85" height="133"&gt;&lt;/a&gt; On the way back we again went back to the Clock tower (choubara) area to pick up some &lt;a href="http://en.wikipedia.org/wiki/Bidriware"&gt;Bidriware&lt;/a&gt; which is specialty of this City. These are hand made by putting in silver threads into copper, zinc allow casts. It’s pleasure to actually see them being made and buy from the artisans directly. Do not buy Bidri from the main road as they’d loot you. Ask for choubara and then when you reach that area ask around for the shops.&lt;/p&gt; &lt;p&gt;It was around 3:30 when we finished our Bidar tour and drove back to Hyd.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Tips:&lt;/strong&gt;&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Carry a map (print-out from Google) for Bidar city if you do not have GPS&lt;/li&gt; &lt;li&gt;Start early so that you can finish the fort before it gets too hot&lt;/li&gt; &lt;li&gt;Ask to be shown around inside Bidar fort and tip at the end&lt;/li&gt; &lt;li&gt;Carry cloth to cover head if you plan to visit the Gurudwara&lt;/li&gt; &lt;li&gt;The Rohit restaurant close to the Gurudwara is highly recommended.&lt;/li&gt; &lt;li&gt;Do buy some Bidriware (small pieces comes for around Rs.200). However, you need to go to choubara area to buy them.&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;If you visit Bidar and want to get something added/updated to this post do leave a comment.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-1018585733578085004?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/1018585733578085004/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=1018585733578085004&amp;isPopup=true" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/1018585733578085004?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/1018585733578085004?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2010/01/bidar-road-trip-from-hyderabad.html" title="Bidar road trip from Hyderabad" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm5.static.flickr.com/4005/4279723296_faf6376364_t.jpg" height="72" width="72" /><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;A0ACSHkzcSp7ImA9WxBRE0s.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-726756682261183699</id><published>2010-01-01T23:46:00.001+05:30</published><updated>2010-01-01T23:46:09.789+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-01-01T23:46:09.789+05:30</app:edited><title>.NETCF: The mini Y2K</title><content type="html">&lt;a title="Kolkata Trip 2009 by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4100462291/"&gt;&lt;img alt="Kolkata Trip 2009" src="http://farm3.static.flickr.com/2740/4100462291_3510b905ab.jpg" width="500" height="449"&gt;&lt;/a&gt;  &lt;p&gt;I am sure most people haven’t yet forgotten the &lt;a href="http://en.wikipedia.org/wiki/Y2K"&gt;Y2K problem&lt;/a&gt;. This year our team faced a mini Y2K, but don’t worry we anticipated it and all is well.&lt;/p&gt; &lt;p&gt;If you head over to &lt;a href="http://en.wikipedia.org/wiki/.NET_Compact_Framework"&gt;NETCF Wikipedia page&lt;/a&gt; you’d notice the NETCF versions look as follows&lt;/p&gt; &lt;p&gt;&amp;lt;MajorVersion&amp;gt;.&amp;lt;MinorVersion&amp;gt;.&amp;lt;Year&amp;gt;&amp;lt;DayofYear&amp;gt;.&amp;lt;Rev&amp;gt;&lt;/p&gt; &lt;p&gt;A sample version number is &lt;/p&gt; &lt;p&gt;3.5.7283.0&lt;/p&gt; &lt;p&gt;This represents .NETCF version 3.5 build on the 283rd day of 2007. I guess by now you can guess the problem. We use a single digit to represent the year. By that nomenclature, the version of the build churned out today would be 3.5.0001.0 which is lower than the one generated the year before and would fail to install. &lt;/p&gt; &lt;p&gt;These numbers are automatically generated by scripts on the server that churns out daily builds. The numbering system was invented a long time ago in early 2000 and no one bothered to fix it. We anticipated that it’s going to fail as we move into the new decade and have updated it to now have 2 digits for the year (and yes we know it will break again in the future, but hopefully that’s too far out to care right now).&lt;/p&gt; &lt;p&gt;Happy new Year.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-726756682261183699?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/726756682261183699/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=726756682261183699&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/726756682261183699?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/726756682261183699?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2010/01/netcf-mini-y2k.html" title=".NETCF: The mini Y2K" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2740/4100462291_3510b905ab_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0MFQH06fyp7ImA9WxBSGUg.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-6290370643744774250</id><published>2009-12-28T03:33:00.001+05:30</published><updated>2009-12-28T03:33:31.317+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-28T03:33:31.317+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Coding / .NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Garbage Collection" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><title>Back to Basics: Memory leaks in managed systems</title><content type="html">&lt;a title="Kolkata Trip 2009 by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4100461749/"&gt;&lt;img alt="Kolkata Trip 2009" src="http://farm3.static.flickr.com/2777/4100461749_c66260f0d0.jpg" width="500" height="375"&gt;&lt;/a&gt;  &lt;p&gt;Someone contacted me over my blog about his managed application where the working set goes on increasing and ultimately leads to out of memory. In the email at one point he states that &lt;strong&gt;he is using .NET and hence there should surely be no leaks&lt;/strong&gt;. I have also talked with other folks in the past where they think likewise.&lt;/p&gt; &lt;p&gt;However, this is not really true. To get to the bottom of this first we need to understand what the the GC does. Do read up &lt;a href="http://blogs.msdn.com/abhinaba/archive/2009/01/20/back-to-basics-why-use-garbage-collection.aspx"&gt;http://blogs.msdn.com/abhinaba/archive/2009/01/20/back-to-basics-why-use-garbage-collection.aspx&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;In summary GC keeps track of object usage and collects/removes those that are no longer referenced/used by any other objects. It ensures that it doesn’t leave dangling pointers. You can find how it does this at &lt;a title="http://blogs.msdn.com/abhinaba/archive/2009/01/25/back-to-basic-series-on-dynamic-memory-management.aspx" href="http://blogs.msdn.com/abhinaba/archive/2009/01/25/back-to-basic-series-on-dynamic-memory-management.aspx"&gt;http://blogs.msdn.com/abhinaba/archive/2009/01/25/back-to-basic-series-on-dynamic-memory-management.aspx&lt;/a&gt;&lt;/p&gt; &lt;p&gt;However, there is some catch to the statement above. The GC can only remove objects that are not in use. Unfortunately it’s easy to get into a situation where your code can result in objects never being completely de-referenced. &lt;/p&gt; &lt;p&gt;&lt;strong&gt;Example 1: Event Handling (discussed in more detail &lt;a href="http://blogs.msdn.com/abhinaba/archive/2009/05/05/memory-leak-via-event-handlers.aspx"&gt;here&lt;/a&gt;).&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Consider the following code&lt;/p&gt;&lt;pre class="code"&gt;EventSink sink = new EventSink();&lt;br /&gt;EventSource src = new EventSource();&lt;br /&gt;&lt;br /&gt;&lt;font color="#00ff00"&gt;src.SomeEvent += sink.EventHandler;&lt;/font&gt;&lt;br /&gt;src.DoWork();&lt;br /&gt;&lt;br /&gt;&lt;font color="#ff8888"&gt;sink = null;&lt;/font&gt;&lt;br /&gt;// Force collection&lt;br /&gt;GC.Collect();&lt;br /&gt;GC.WaitForPendingFinalizers();&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;In this example at the point where we are forcing a GC there is no reference to sink (explicitly via &lt;font face="Courier New"&gt;sink = null&lt;/font&gt; ), however, even then sink will not be collected. The reason is that sink is being used as an event handler and hence src is holding an reference to sink (so that it can callback into sink.EventHandler once the src.SomeEvent is fired) and stopping it from getting collected&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Example 2: Mutating objects in collection (discussed &lt;a href="http://blogs.msdn.com/abhinaba/archive/2007/10/18/mutable-objects-and-hashcode.aspx"&gt;here&lt;/a&gt;)&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;There can be even more involved cases. Around 2 years back I saw an issue where objects were being placed inside a Dictionary and later retrieved, used and discarded. Now retrieval was done using the object key. The flow was something like&lt;/p&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Create Object and put it in a Dictionary &lt;br /&gt;&lt;li&gt;Later get object using object key &lt;br /&gt;&lt;li&gt;Call some functions on the object &lt;br /&gt;&lt;li&gt;Again get the object by key and remove it &lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;p&gt;Now the object was not immutable and in using the object in step 3 some fields of that object got modified and the same field was used for calculating the objects hash code (used in overloaded GetHashCode). This meant the Remove call in step 4 didn’t find the object and it remained inside the dictionary. Can you guess why changing a field of an object that is used in GetHashCode fails it from being retrieved from the dictionary? Check out &lt;a title="http://blogs.msdn.com/abhinaba/archive/2007/10/18/mutable-objects-and-hashcode.aspx" href="http://blogs.msdn.com/abhinaba/archive/2007/10/18/mutable-objects-and-hashcode.aspx"&gt;http://blogs.msdn.com/abhinaba/archive/2007/10/18/mutable-objects-and-hashcode.aspx&lt;/a&gt; to know why this happens.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;There are many more examples where this can happen.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;So we can conclude that memory leaks is common in managed memory as well but it typically happens a bit differently where some references are not cleared as they should’ve been and the GC finds these objects referenced by others and does not collect them.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-6290370643744774250?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/6290370643744774250/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=6290370643744774250&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/6290370643744774250?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/6290370643744774250?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2009/12/back-to-basics-memory-leaks-in-managed.html" title="Back to Basics: Memory leaks in managed systems" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2777/4100461749_c66260f0d0_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DkIHQ3cyfSp7ImA9WxBSFE0.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-8124441106561566652</id><published>2009-12-21T19:38:00.001+05:30</published><updated>2009-12-21T19:38:52.995+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-21T19:38:52.995+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Everything Else" /><category scheme="http://www.blogger.com/atom/ns#" term="Software" /><title>Some things I have learnt amount SW development</title><content type="html">&lt;a title="Kolkata Trip 2009 by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4100451045/"&gt;&lt;img alt="Kolkata Trip 2009" src="http://farm3.static.flickr.com/2533/4100451045_4bda3b0517.jpg" width="500" height="420"&gt;&lt;/a&gt;  &lt;p&gt;Working in the developer division is very exciting because I can relate so well with the customers. However, that is also an issue. You relate so well that you tend to evolve some strong opinions that can cloud your view. While working in the Visual Studio Team System team and now in the .NET Compact Framework team I have learnt some lessons. I thought I’d share some of them&lt;/p&gt; &lt;p&gt;&lt;strong&gt;I am not *the* customer (or rather the only customer) &lt;br&gt;&lt;/strong&gt;Even though I represent the customer in different avatars (sometimes as a developer, sometimes as an office worker, sometimes just as a geek) I am not THE only customer that the product targets. When your product is going to be used by 100,000 developers/testers the average or even the predominant usage is going to be very different from what you think it will be. Sitting though an usability study is a very humbling experience. Like I believed that everyone should just be using incremental search.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Consistency is important &lt;br&gt;&lt;/strong&gt;Geeks and bloggers tend to over-tout coolness. While cool user experience (UX) seems awesome, it is frequently overdone and what seems cool on casual usage tends to tire soon. Consistency on the other hand lets your users get on-board faster and lets them spend time doing stuff they care about and not learning things that should work automatically. &lt;/p&gt; &lt;p&gt;Consistency doesn’t mean that every application needs to look exactly like notepad. Expression Blend is a great example which looks refreshingly cool (appeals to the designers) and at the same time provides an experience that is consistent to other windows apps. &lt;/p&gt; &lt;p&gt;&lt;strong&gt;Learn to let go &lt;br&gt;&lt;/strong&gt;”If there’s not something you can actively do on a project, if it’s something you can only influence and observe, then you have to learn to provide your feedback, and then let go and allow other people to fail… People don’t learn if they never make any mistakes” ~ &lt;a href="http://www.microspotting.com/2009/01/raymond-chen"&gt;Raymond Chen on Microspotting&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Corporate software development is very different from Indie development. Large software development projects have a bunch of people/teams involved. It is not necessary that the collective opinion matches yours. At some point you need to learn to let go and do what is required. As an example I can debate on what a Debug Assert dialog should look like or do. However, there are other folks to design and think about the UX, as a developer I need to give inputs and once the call has been made it’s my job to provide the best engineering solution that implements that UX**.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;** Do note the debug assert dialog is a fictitious example, I never worked on the IDE side.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-8124441106561566652?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/8124441106561566652/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=8124441106561566652&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/8124441106561566652?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/8124441106561566652?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2009/12/some-things-i-have-learnt-amount-sw.html" title="Some things I have learnt amount SW development" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2533/4100451045_4bda3b0517_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEcARno_fCp7ImA9WxBSEkQ.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-6292103490225848972</id><published>2009-12-20T13:30:00.001+05:30</published><updated>2009-12-20T13:30:47.444+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-20T13:30:47.444+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Technology" /><category scheme="http://www.blogger.com/atom/ns#" term="Amazing India" /><category scheme="http://www.blogger.com/atom/ns#" term="Everything Else" /><category scheme="http://www.blogger.com/atom/ns#" term="Software" /><title>Indic Language Input</title><content type="html">&lt;a title="Diwali 2009 by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4021549307/"&gt;&lt;img alt="Diwali 2009" src="http://farm3.static.flickr.com/2474/4021549307_bb5bd6cbb0.jpg" width="500" height="320"&gt;&lt;/a&gt;  &lt;p&gt;If you have tried inputting Indian languages in Windows you know it’s a major pain. That is particularly sad because Windows comes with very good support of Indian languages. I had almost given up using my native language Bengali on a computer due to this. Even when I was creating the &lt;a href="http://blogs.msdn.com/abhinaba/about.aspx"&gt;About Page&lt;/a&gt; for this blog and wanted to have a version in Bengali, I had to cut it short a lot because typing it out was so painful.&lt;/p&gt; &lt;p&gt;There are web-based tools like the &lt;a href="http://www.google.com/transliterate/indic/BENGALI"&gt;Google Transliteration tool&lt;/a&gt; that works well for entering text into web-pages where they are integrated (e.g. &lt;a href="http://www.orkut.com/"&gt;Orkut&lt;/a&gt;). However, I wanted a solution that pans the desktop, so that I can use it for say writing a post using &lt;a href="http://windowslivewriter.spaces.live.com/"&gt;Windows Live Writer&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;Enter the &lt;a href=" http://specials.msn.co.in/ilit/Bengali.aspx"&gt;Microsoft Indic Language Input tool&lt;/a&gt;. Head over to the link and install the desktop version. You can install the various languages individually (currently &lt;a href="http://specials.msn.co.in/ilit/Bengali.aspx"&gt;Bengali&lt;/a&gt;, &lt;a href="http://specials.msn.co.in/ilit/Hindi.aspx"&gt;Hindi&lt;/a&gt;, &lt;a href="http://specials.msn.co.in/ilit/Kannada.aspx"&gt;Kannada&lt;/a&gt;, &lt;a href="http://specials.msn.co.in/ilit/Malayalam.aspx"&gt;Malayalam&lt;/a&gt;, &lt;a href="http://specials.msn.co.in/ilit/Tamil.aspx"&gt;Tamil&lt;/a&gt; and &lt;a href="http://specials.msn.co.in/ilit/Telugu.aspx"&gt;Telugu&lt;/a&gt; is supported). I personally installed the Bengali and Hindi versions. &lt;/p&gt; &lt;p&gt;Since I am on Windows 7 which comes pre-installed with Complex language support I needn’t do anything special. However, on older OS like XP you need to do some extra steps which are available through the &lt;a href="http://specials.msn.co.in/ilit/GettingStarted.aspx"&gt;Getting Started&lt;/a&gt; link on that page.&lt;/p&gt; &lt;p&gt;Once you are setup you can keep the Windows Language Bar floating on the desktop. The tool extends the language bar to allow you to enter Indic languages using an English keyboard via transliteration.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_DLceQ4wfZNI/Sy3Zd4yRuOI/AAAAAAAAAL8/kcSmXboeoAg/s1600-h/image19.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_DLceQ4wfZNI/Sy3ZelAQCiI/AAAAAAAAAMA/ApRJP8QiR4s/image_thumb11.png?imgmax=800" width="260" height="100"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Go to the application where you want to enter Indic language and then switch to Bengali (or any of the other 6 supported Indic language) using this language bar. Start typing বেঙ্গলি using English keyboard and the tool will transliterates. The moment you’d hit a word terminator like space it inserts the Bengali word.&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_DLceQ4wfZNI/Sy3ZfRDx51I/AAAAAAAAAME/siBTMSXobUo/s1600-h/image18.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_DLceQ4wfZNI/Sy3ZgARGhXI/AAAAAAAAAMI/afQPJCksrOQ/image_thumb10.png?imgmax=800" width="388" height="310"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;I tried some difficult words like কিংকর্তববিমূঢ় and it worked amazingly well&lt;/p&gt; &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_DLceQ4wfZNI/Sy3Zg76wwLI/AAAAAAAAAMM/kYkeKqPC5aA/s1600-h/image17.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_DLceQ4wfZNI/Sy3ZhRR3HzI/AAAAAAAAAMQ/fqkUdNe3nDg/image_thumb9.png?imgmax=800" width="322" height="250"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;I had a very good experience with the tool. The only issue I faced was that the tool was extremely slow with some WPF apps like &lt;a href="http://seesmic.com/seesmic_desktop/"&gt;Seesmic twitter client&lt;/a&gt;. However, I got to know from the dev team that they are aware of the issue (it’s for some specific WPF apps and not WPF in general). I hope they fix it before they RTM (the tool is in Beta).&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; You can hit alt+shift to cycle the various languages in the toolbar without having to use your mouse (which is handy if you typing using a mix of languages).&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-6292103490225848972?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/6292103490225848972/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=6292103490225848972&amp;isPopup=true" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/6292103490225848972?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/6292103490225848972?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2009/12/indic-language-input.html" title="Indic Language Input" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2474/4021549307_bb5bd6cbb0_t.jpg" height="72" width="72" /><thr:total>3</thr:total></entry><entry gd:etag="W/&quot;CUIHSX0yeCp7ImA9WxNaGUw.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-4218358645629429132</id><published>2009-12-04T13:28:00.001+05:30</published><updated>2009-12-04T13:28:58.390+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-12-04T13:28:58.390+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Coding / .NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Garbage Collection" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><title>NETCF: Count your bytes correctly</title><content type="html">&lt;a title="Pirate by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/4021545147/"&gt;&lt;img alt="Pirate" src="http://farm3.static.flickr.com/2793/4021545147_13c0a876f4.jpg" width="500" height="426"&gt;&lt;/a&gt;  &lt;p&gt;I got a stress related issue reported in which the code tried allocating a 5MB array and do some processing on it but that failed with OOM (Out of Memory). It also stated that there was way more than 5 MB available on the device and surely it’s some bug in the Execution Engine.&lt;/p&gt; &lt;p&gt;Here’s the code.&lt;/p&gt;&lt;pre class="code"&gt;try{&lt;br /&gt;    byte[] result;&lt;br /&gt;    long GlobalFileSize = 5242660;  &lt;font color="#00cc00"&gt;//5MB&lt;/font&gt;&lt;br /&gt;    result = new byte[GlobalFileSize];&lt;br /&gt;    string payload = Encoding.UTF8.GetString(result, 0, result.Length);&lt;br /&gt;    System.Console.WriteLine("len " + payload.Length);&lt;br /&gt;}&lt;br /&gt;catch (Exception e)&lt;br /&gt;{&lt;br /&gt;    System.Console.WriteLine("Exception " + e); &lt;br /&gt;} &lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The problem is that the user didn’t count his bytes well. The array is 5MB and it actually gets allocated correctly. The problem is with the memory complexity of the UTF8.GetString which allocates further memory based on it’s input. In this particular case the allocation pattern goes something like&lt;/p&gt;&lt;pre&gt;  5MB  -- Byte Array allocation (as expected and works)&lt;br /&gt;&lt;br /&gt;  5MB  -- Used by GetString call&lt;br /&gt; 10MB  -- Used by GetString call&lt;br /&gt;  5MB  -- Used by GetString call&lt;br /&gt; 10MB  -- Used by GetString call&lt;/pre&gt;&lt;br&gt;&lt;br /&gt;&lt;p&gt;So GetString needed a whooping 30MB and the total allocation is around 35MB which was really not available.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Morale of the story&lt;/em&gt;&lt;/strong&gt;: Count your bytes well, preferably through a tool like &lt;a href="http://blogs.msdn.com/stevenpr/archive/2007/03/08/finding-managed-memory-leaks-using-the-net-cf-remote-performance-monitor.aspx"&gt;Remote Performance Monitor&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-4218358645629429132?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/4218358645629429132/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=4218358645629429132&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/4218358645629429132?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/4218358645629429132?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2009/12/netcf-count-your-bytes-correctly.html" title="NETCF: Count your bytes correctly" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2793/4021545147_13c0a876f4_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;Ak4MRnY8cSp7ImA9WxNbFE4.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-4819253232670820912</id><published>2009-11-17T11:53:00.001+05:30</published><updated>2009-11-17T11:53:07.879+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-17T11:53:07.879+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Software" /><category scheme="http://www.blogger.com/atom/ns#" term="Silverlight" /><title>Silverlight: Where are my colors</title><content type="html">&lt;a title="Barsha Mangal by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/3757657932/"&gt;&lt;img alt="Barsha Mangal" src="http://farm4.static.flickr.com/3469/3757657932_cd7a855468.jpg" width="500" height="354"&gt;&lt;/a&gt;&amp;nbsp; &lt;p&gt;The Silverlight &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.colors_members(VS.95).aspx"&gt;System.Windows.Media.Colors&lt;/a&gt; class is a trimmer counterpart of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.colors_members(VS.100).aspx"&gt;WPF Colors&lt;/a&gt; class. E.g. Colors.AliceBlue is available in WPF but not present in Silverlight. However, these standard colors are indeed available in Silverlight XAML. &lt;/p&gt; &lt;p&gt;In effect in Silverlight XAML you can use &lt;/p&gt;&lt;pre&gt;&amp;lt;Border Background="&lt;strong&gt;AliceBlue&lt;/strong&gt;" BorderBrush="&lt;strong&gt;Coral&lt;/strong&gt;" BorderThickness="2" CornerRadius="10" &amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;However, if you try that in code it fails to compile&lt;/p&gt;&lt;pre&gt;foo.Background = new SolidColorBrush(Colors.Coral);&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;This means if you ever need to use standard colors in Silverlight code you have to use RGB values, which for Coral would be something like&lt;/p&gt;&lt;pre&gt;foo.Background = new SolidColorBrush(Color.FromArgb(255,255,127,80));&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;This is kind of painful. Moreover, you need to frequently be able to convert between HTML color, RGB and XAML standard color names when you are developing an Silverlight application. To make the job easier I hacked up a small Silverlight 2 app at &lt;a title="http://www.bonggeek.com/Ag/Colors/" href="http://www.bonggeek.com/Ag/Colors/"&gt;http://www.bonggeek.com/Ag/Colors/&lt;/a&gt;. You can do the following with this&lt;/p&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;Change colors with sliders, RGB, HTML, XAML standard color names to see what the color really looks like &lt;br /&gt;&lt;li&gt;All the format is kept in sync, this means if you change the sliders to get to the color Salmon then the RGB value and HTML will be updated and the drop down will switch to show the selected colors name &lt;br /&gt;&lt;li&gt;You can easily create variants of standard color. E.g. select Salmon using the drop down and then push the sliders to get to a slightly lighter/darker shade of the color&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_DLceQ4wfZNI/SwJBR-ylVBI/AAAAAAAAAL0/58e1bhWFbzk/s1600-h/image%5B4%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_DLceQ4wfZNI/SwJBSiSGXlI/AAAAAAAAAL4/Xo3H0RDT4uY/image_thumb%5B2%5D.png?imgmax=800" width="545" height="773"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Enjoy and extend as you please. Sources are available &lt;a href="http://cid-bb138c80f00ddb60.skydrive.live.com/self.aspx/Public/Blog/ColorSlider.zip "&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-4819253232670820912?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/4819253232670820912/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=4819253232670820912&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/4819253232670820912?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/4819253232670820912?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2009/11/silverlight-where-are-my-colors.html" title="Silverlight: Where are my colors" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm4.static.flickr.com/3469/3757657932_cd7a855468_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D04GQXw5fSp7ImA9WxNRFkk.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-1736379901978666123</id><published>2009-09-11T10:42:00.000+05:30</published><updated>2009-09-11T10:42:00.225+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-11T10:42:00.225+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><category scheme="http://www.blogger.com/atom/ns#" term="S60" /><title>Global variables are bad</title><content type="html">&lt;a title="Hyderabad Zoological Park by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/3675501552/"&gt;&lt;img alt="Hyderabad Zoological Park" src="http://farm3.static.flickr.com/2522/3675501552_494d6ba11b.jpg" width="500" height="457"&gt;&lt;/a&gt;  &lt;p&gt;&lt;strong&gt;&amp;lt;This post is about C++ (C# folks are saved from this pain)&amp;gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;One of our devs taking care of NETCF on Nokia S60 reported that after the latest code reached their branch things are working very slow. It was observed that Garbage Collector is getting kicked in way more than it should. Investigation showed something interesting.&lt;/p&gt; &lt;p&gt;I added a global var gcConfig which had a fairly complex constructor and that among other things sets the various member variables like the GC trigger threshold to default value (1mb). All of these works fine on Windows variants.&lt;/p&gt; &lt;p&gt;However, &lt;a href="http://en.wikipedia.org/wiki/The_C%2B%2B_Programming_Language"&gt;TCPL&lt;/a&gt; states “&lt;i&gt;It is generally best to minimize the use of global variables and in particular to &lt;u&gt;limit the use of global variables requiring complicated initialization&lt;/u&gt;.&lt;/i&gt;”. This is especially true for dlls. We tend to ignore good advice sometimes :)&lt;/p&gt; &lt;p&gt;For Symbian OS (S60) &lt;u&gt;on device&lt;/u&gt; complex ctors of global objects are not run (without any warning). The members are all set to 0 (default member initialization). So in the gcConfig GC-trigger was being set to 0 instead of 1mb. The allocation byte count is compared against this value &lt;a href="http://blogs.msdn.com/abhinaba/archive/2009/03/23/net-compact-framework-gc-quantum.aspx"&gt;to figure out when it’s time to start a GC&lt;/a&gt;. Since it was 0 the collection condition is being met for every allocation and hence for every allocation request GC was being fired!!!&lt;/p&gt; &lt;p&gt;Actually considering that even after that the app was actually running shows that we have pretty good perf ;)&lt;/p&gt; &lt;p&gt;A good alternative of using global vars is as follows&lt;/p&gt;&lt;pre class="Code"&gt;MyClass&amp;amp; useMC()&lt;br&gt;{&lt;br&gt;    static MyClass mc; // static ensures objects are not created on each call&lt;br&gt;    return mc;&lt;br&gt;}&lt;br&gt;&lt;br&gt;MyClass&amp;amp; mc = useMC();&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Do note that this has some multi-threading issue. See &lt;a href="http://blogs.msdn.com/oldnewthing/archive/2004/03/08/85901.aspx"&gt;http://blogs.msdn.com/oldnewthing/archive/2004/03/08/85901.aspx&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-1736379901978666123?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/1736379901978666123/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=1736379901978666123&amp;isPopup=true" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/1736379901978666123?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/1736379901978666123?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2009/09/global-variables-are-bad.html" title="Global variables are bad" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2522/3675501552_494d6ba11b_t.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DkIGSHYzcSp7ImA9WxNRFEo.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-6380466591380024064</id><published>2009-09-08T10:42:00.000+05:30</published><updated>2009-09-09T11:05:29.889+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-09T11:05:29.889+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><title>.NET Compact Framework BCL &lt; .NET BCL</title><content type="html">&lt;a title="Hyderabad Zoological Park by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/3674684695/"&gt;&lt;img alt="Hyderabad Zoological Park" src="http://farm3.static.flickr.com/2546/3674684695_137c7efb62.jpg" width="500" height="405"&gt;&lt;/a&gt;  &lt;p&gt;Over twitter some folks are regularly discussing about the fact that there are some chunks of desktop .NET Base class library (BCL) that are missing on the .NET Compact Framework (.NETCF). So I thought I’d post the rationale behind things that are missing and what criteria is used to figure out what makes it in.&lt;/p&gt; &lt;p&gt;First of all, .NET and .NETCF use completely different runtimes. So the BCL code doesn’t work as is. They need to be ported over. Something being available on the desktop reduces the effort of our BCL team but still significant cost is involved in making it work over NETCF. This means that its not as if everything is available on .NETCF BCL and we cut things out (elimination process), but the other way round where we start from 0 and we need to figure out whether we can take something in. In that process we use some of the following rationale.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;b&gt;ROI:&lt;/b&gt; Does the user scenario that it enables on a mobile device justify the cost&lt;br&gt;System.CodeDom.Compiler. Yea right you expected to compile on the phone didn’t you :) &lt;br&gt; &lt;li&gt;&lt;b&gt;Easy workaround available&lt;/b&gt;: If there is an acceptable workaround for a given API then it drops in priority. A trivial example could be that we ship some method overloads but not the other. E.g. Instead of shipping all overloads of Enum.Parse we drop Enum.Parse(Type, String) and keep only Enum.Parse(Type, String, Bool).&lt;br&gt;This applies at the level of namespace or Types as well.&lt;br&gt; &lt;li&gt;&lt;b&gt;Lower in priority list:&lt;/b&gt; It needs work to get it done and it’s lower in priority than other things that is keeping the engineering team busy. &lt;br&gt;If there are a lot of request for these features and not good/performant workarounds available then it will go up the priority list and make it to future version of NETCF&lt;br&gt; &lt;li&gt;&lt;b&gt;Too large to fit:&lt;/b&gt; Simply too large to fit into our memory limitations&lt;br&gt;E.g. Reflection.Emit which leads to other things missing like Dynamic Language Runtime, Linq-to-SQL &lt;br&gt; &lt;li&gt;&lt;b&gt;No native support:&lt;/b&gt; It uses some underlying OS feature which is either not present on devices or is not relevant to it&lt;br&gt;WPF, Parallel computing support&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;With every release developers ask for new features and we also negotiate to increase NETCF footprint budget so that we can include some (but not all) from those requests. To choose what makes it in we use some of the criteria mentioned above.&lt;/p&gt; &lt;p&gt;Given the system constraints under which NETCF works a vast majority of the desktop APIs will continue to be missing from NETCF. Hopefully this gives you some context behind why those are missing. If you approach NETCF simply from trying to port a desktop application then you would face some frustration on the missing surface area.&lt;/p&gt; &lt;p&gt;BTW: Do post your comments on this blog or on &lt;a href="http://www.twitter.com"&gt;twitter&lt;/a&gt; (use the #netcf hashtag).&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&amp;lt;Update: I made some updates to this based on feedback /&amp;gt;&lt;/strong&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-6380466591380024064?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/6380466591380024064/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=6380466591380024064&amp;isPopup=true" title="14 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/6380466591380024064?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/6380466591380024064?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2009/09/net-compact-framework-bcl-net-bcl.html" title=".NET Compact Framework BCL &amp;lt; .NET BCL" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2546/3674684695_137c7efb62_t.jpg" height="72" width="72" /><thr:total>14</thr:total></entry><entry gd:etag="W/&quot;AkQGQXo8cCp7ImA9WxNSGEs.&quot;"><id>tag:blogger.com,1999:blog-6434675.post-3390148251846699844</id><published>2009-09-02T10:42:00.000+05:30</published><updated>2009-09-02T10:42:00.478+05:30</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-09-02T10:42:00.478+05:30</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Coding / .NET" /><category scheme="http://www.blogger.com/atom/ns#" term="Garbage Collection" /><category scheme="http://www.blogger.com/atom/ns#" term=".NET CF" /><category scheme="http://www.blogger.com/atom/ns#" term="Software" /><title>NETCF: GC and thread blocking</title><content type="html">&lt;a title="Hyderabad Zoological Park by abhinaba, on Flickr" href="http://www.flickr.com/photos/abhinaba/3674696765/"&gt;&lt;img alt="Hyderabad Zoological Park" src="http://farm3.static.flickr.com/2579/3674696765_49605f192a.jpg" width="500" height="375"&gt;&lt;/a&gt;  &lt;p&gt;One of our customers asked us a bunch of questions on the NETCF garbage collector that qualifies as FAQ and hence I thought I’d put them up here.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Question: What is the priority of the GC thread&lt;/strong&gt; &lt;br&gt;&lt;strong&gt;Answer: &lt;/strong&gt;Unlike some variants of the desktop GC and other virtual machines (e.g. JScript) we do not have any background or timer based GC. The CLR fires GC on the same thread that tried allocation and either the allocation failed or during pre-allocation checks the CLR feels that &lt;a href="http://blogs.msdn.com/abhinaba/archive/2008/04/29/when-does-the-net-compact-framework-garbage-collector-run.aspx"&gt;time to run GC has come&lt;/a&gt;. So the priority of the GC thread is same as that of the thread that resulted in GC.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Question: Can the GC freeze managed threads that are of higher priority than the GC thread?&lt;/strong&gt; &lt;br&gt;&lt;strong&gt;Answer:&lt;/strong&gt; Yes GC can freeze managed threads which has higher priority than itself. Before actually running GC the CLR tries to go into a “safe point”. Each thread has a suspend event associated with it and this event is checked by each thread regularly. Before starting GC the CLR enumerates all managed threads and in each of them sets this event. In the next point when the thread checks and finds this event set, it blocks waiting for the event to get reset (which happens when GC is complete). This mechanism is agnostic of the relative priority of the various threads.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Question: Does it freeze &lt;u&gt;all&lt;/u&gt; threads or only Managed threads?&lt;/strong&gt; &lt;br&gt;&lt;strong&gt;Answer:&lt;/strong&gt; The NETCF GC belongs to the category “stop-the-world GC”. It needs to freeze threads so that when it is iterating and compacting managed heap nothing on it gets modified. This is unlike some background/incremental GC supported by other virtual machines.&lt;/p&gt; &lt;p&gt;GC freezes only managed threads and not other native threads (e.g. COM or host-threads). However, there are two exclusions even on the managed threads&lt;/p&gt; &lt;ol&gt; &lt;li&gt;It doesn’t freeze the managed thread that started GC because the GC will be run on that thread (see answer to first question)  &lt;li&gt;Managed threads that are currently executing in native p/invoke code is not frozen either. However, the moment they try to return to managed execution they get frozen. (I actually missed this subtle point in my response and Brian caught it :)) &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Hope this answers some of your questions. &lt;strong&gt;Feel free to send me any .NET Compact Framework CLR questions. I will either answer them myself or get someone else to do it for you :)&lt;/strong&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6434675-3390148251846699844?l=geekgyan.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://geekgyan.blogspot.com/feeds/3390148251846699844/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.blogger.com/comment.g?blogID=6434675&amp;postID=3390148251846699844&amp;isPopup=true" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/3390148251846699844?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/6434675/posts/default/3390148251846699844?v=2" /><link rel="alternate" type="text/html" href="http://geekgyan.blogspot.com/2009/09/netcf-gc-and-thread-blocking.html" title="NETCF: GC and thread blocking" /><author><name>Abhinaba Basu</name><uri>http://www.blogger.com/profile/17653254493243741669</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://4.bp.blogspot.com/-B9x5HwinoqE/Tfeydlk4Z_I/AAAAAAAAAWQ/s5E8vqf1yUI/s220/Abhinaba.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://farm3.static.flickr.com/2579/3674696765_49605f192a_t.jpg" height="72" width="72" /><thr:total>3</thr:total></entry></feed>

