tag:blogger.com,1999:blog-22541117569878388502012-07-30T08:38:44.868-07:00My Technical StuffShweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.comBlogger44125tag:blogger.com,1999:blog-2254111756987838850.post-2496305961761844572012-07-28T07:33:00.001-07:002012-07-30T08:38:44.913-07:002012-07-30T08:38:44.913-07:00Strange fact about GetHashCode()<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #134f5c; display: inline !important; float: none; font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">While doing one of my asisgnment, I came across a strange fact about GetHashCode() in C#. Object.GetHashCode() tells that String class returns identical hash codes for identical strings. <span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; display: inline !important; float: none; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">But after doing some experiments, I found that above mentioned statement is bit misleading. Actually, it varies from architecture-to-architecture, depending upon, whether one is using 32-bit or 64-bit machine. To prove this, I created a sample application in C#.</span></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #134f5c; display: inline !important; float: none; font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; display: inline !important; float: none; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><br /></span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="clear: left; color: #134f5c; float: left; font-family: Arial, Helvetica, sans-serif; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="67" src="http://2.bp.blogspot.com/-K46A2JBU3dA/UBP0UIPN7eI/AAAAAAAAAGE/Ae7FqXF7jXw/s400/1.PNG" width="400" /></span></div>
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; display: inline !important; float: none; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; font-size: small;">
</span></span><br />
<br />
<br />
<div class="MsoNormal" style="margin: 0cm 0cm 10pt;">
<br />
I ran above snippet on 32-bit windows machine and found
below result:</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-UH5J9eMeGIM/UBP0ViMS0PI/AAAAAAAAAGM/i26Gy_NARBs/s1600/2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><img border="0" src="http://3.bp.blogspot.com/-UH5J9eMeGIM/UBP0ViMS0PI/AAAAAAAAAGM/i26Gy_NARBs/s1600/2.PNG" /></span></a><span style="background-color: white; font-size: 13px; text-align: -webkit-auto;"></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><span style="background-color: white; text-align: -webkit-auto;">then I ran the same code on 64-bit machine and come up with below result</span><span style="background-color: white; text-align: -webkit-auto;">:</span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-KmAJK8ungoU/UBP2Hv_dgGI/AAAAAAAAAGc/ja12iRK45g8/s1600/3.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><img border="0" src="http://4.bp.blogspot.com/-KmAJK8ungoU/UBP2Hv_dgGI/AAAAAAAAAGc/ja12iRK45g8/s1600/3.PNG" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="text-align: -webkit-auto;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Now looking at above results, one can easily conclude about the behaviour of GetHashCode(). So, beware and think atleast twice, before using GetHashCode() for strings, as it may give different-different results on different-different platforms.</span></span>
</div>
<br />
<span style="font-family: 'Times New Roman'; font-size: small;">
</span><a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display: none;">CodeProject</a></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-249630596176184457?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-48208299899583228382012-06-16T01:33:00.000-07:002012-06-16T02:05:14.860-07:002012-06-16T02:05:14.860-07:00Submitting a HPC job from on-premise - Part 2 of 2<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Continuing with my previous
article, today I am going to share my one more experience with HPC. Nowadays, there are lots of links available on
net, which tell, how to submit a job to Azure HPC Scheduler. I also explored
most of them, and found that almost all are talking about job submission from
cloud premise(Front or Head node). But nowhere was it mentioned how to submit a
job from outside of cloud vicinity. I came across this issue, while working on
one of my assignments.</span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">After hitting
my head, finally I found a way to do this. When we are talking about
interaction between cloud and on-premise, then first thing come into our mind
is network. Here definitely, TCP won’t work. There are few transport schemes
available in Azure HPC framework. After exploring them, I found one as WebAPI
and wow, that suits my requirement. I just used WebAPI as transport scheme, by modifying the name of the headnode to complete host name <b>(i.e. <headNodeName>.cloudapp.net) </b>and get my issue resolved. Sample code is as:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-0wA5slHN0wU/T9xIedVin0I/AAAAAAAAAFw/74yQhAjoJaU/s1600/HPCShweta.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="78" src="http://3.bp.blogspot.com/-0wA5slHN0wU/T9xIedVin0I/AAAAAAAAAFw/74yQhAjoJaU/s320/HPCShweta.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><b>Note</b>:</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">If if everything(service name, head node, etc...) is configured properly, even then you are getting ex</span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">ception like, </span><b style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">‘Fail to get the
cluster name’</b><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">. Then just redeploy the HPC scheduler package and try it again. I know, this is painful but this is the only solution, I came across. And believe me, this was just clicked for me.</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify;">
<br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Hope it will be helpful, for those who get stuck
with similar kind of issue.</span></div>
</div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-4820829989958322838?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-78307098891353470072012-06-02T13:03:00.000-07:002012-06-16T02:05:04.852-07:002012-06-16T02:05:04.852-07:00My first day on Microsoft Windows Azure HPC - Part 1 of 2<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Recently I entered into the Azure’s HPC world and thought to
share something, which I learnt from my experience as a beginner. Today is my
first step towards the Azure’s HPC. I
just downloaded the sample service and followed the configuration instructions.
But even after following those, I faced few difficulties during this journey. So,
here I am sharing that experience only. Hope it will be useful for all newbies.</span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">I feel that below are the few points, which are directly
related to the application performance.</span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><span style="text-indent: -18pt;">1)</span><span style="font-size: 7pt; text-indent: -18pt;">
</span><span style="text-indent: -18pt;"><b><u>Affinity Group</u></b> – While working on cloud, the
first thing comes into mind is performance and throughput. And in order to gain
better throughput and performance, one need to make sure that all our services
and storage accounts hosted on the cloud are located in proximity, which will
reduce data transfer time. So, to bring all the services and storage closer, we
can keep all of them in a group. And in Azure’s term, this group is called as
Affinity Group. So, creating an affinity group will increase data transfer
speed till very high extent. So, it is always a good practice to create our own
affinity group as a first and foremost step.</span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><span style="text-indent: -18pt;"><br /></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><span style="text-indent: -18pt;">2)</span><span style="font-size: 7pt; text-indent: -18pt;">
</span><span style="text-indent: -18pt;"><b><u>Storage Account and Affinity Group</u></b> – Whenever
HPC is configured using sample service, one storage account is being created automatically.
</span><span style="text-indent: -18pt;"> </span><span style="text-indent: -18pt;">This storage account is created
anywhere, irrespective of the affinity group created. One important point to
note here is to; check the affinity group of this newly created storage
account. If it is in the same affinity group which we created for our app, then
great, we need not to do anything :) .</span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><span style="text-indent: -18pt;"><br /></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><span style="text-indent: -18pt;">But in case, if it is not lying in the same
group, then we have to bring that storage account into our already created
affinity group. As of today, there is no direct way to bring the storage
account into our desired affinity group or let’s say, there is no such way for
storage account to switch between affinity groups. The only solution available
is, delete the automatically created storage account (newly created one) and
create new storage account. While creating new storage account from scratch, we
can easily assign the desired affinity group and at the same time, one can skip
the statements in the Azure Sample Service code where it tries to create the
storage account.</span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><span style="text-indent: -18pt;"><br /></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><span style="text-indent: -18pt;">3)</span><span style="font-size: 7pt; text-indent: -18pt;">
</span><span style="text-indent: -18pt;"><b><u>Location</u></b> – While configuring HPC scheduler, the
following steps are accomplished:</span></span></div>
<div class="MsoNormal">
</div>
<ul style="text-align: left;">
<li style="text-align: justify;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; text-indent: -18pt;"> Selection of location (i.e. South East Asia)</span></li>
<li style="text-align: justify;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; text-indent: -18pt;"> </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; text-indent: -18pt;">HPC scheduler randomly selects one of the configured
database server located in the above selected location (here it is South East
Asia)</span></li>
<li style="text-align: justify;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; text-indent: -18pt;"> O</span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; text-indent: -18pt;">nce the database server is selected, next step
is to supply credentials to access/create the database</span></li>
<li style="text-align: justify;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; text-indent: -18pt;"> </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; font-size: 7pt; text-indent: -18pt;"> </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; text-indent: -18pt;">Now the issue here is, how to get user
credentials for this randomly selected database server.</span></li>
</ul>
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"></span><br />
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">To
overcome this issue, as of today, the only solution possible is to modify the
source code in the sample service and mentioned the name of the desired
database server for which user credentials are known.</span></div>
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">
</span><br />
<div class="MsoListParagraphCxSpLast" style="margin-left: 72pt; text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 72pt; text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;"><b style="color: #134f5c;"><u>More info</u></b><span style="color: #134f5c;"> - Whenever someone talks about HPC scheduler, the first thing
which hits our mind is Head Node and the Compute nodes. Head node plays a vital
role, while talking about Windows Azure HPC Scheduler. One can learn more about
HPC Scheduler at </span><span style="color: #3d85c6;"><a href="http://msdn.microsoft.com/en-us/library/windowsazure/hh545593.aspx">http://msdn.microsoft.com/en-us/library/windowsazure/hh545593.aspx</a></span><span style="color: #134f5c;"> .The main purpose of Head node is to distribute jobs/tasks among all available
Compute nodes. One can download the sample (Windows Azure HPC Scheduler code
sample) from Azure website </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;"><a href="http://code.msdn.microsoft.com/windowsazure/Windows-Azure-HPC-7d75eb26">http://code.msdn.microsoft.com/windowsazure/Windows-Azure-HPC-7d75eb26</a></span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"> and follow the steps to configure HPC Scheduler.</span></div>
<div class="MsoNormal" style="text-align: justify;">
</div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 72pt; text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 72pt; text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: 72pt; text-align: justify;">
<br />
<a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display: none;">CodeProject</a></div>
</div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-7830709889135347007?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-56194154394545904082012-05-27T05:52:00.000-07:002012-05-27T05:57:08.361-07:002012-05-27T05:57:08.361-07:00Split multi page tiff file - (C# code attached)<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="text-align: -webkit-auto;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">While working with image files, one of the biggest constraint is the size of file. When file is too big, then it need too much time to process add load. So, to resolve this issue, we can split one big image (tiff) file into various pages. This code sample will explain how to work with TIFF (Tagged Image File Format) using c#.net. It will cover splitting a multipage tiff file into multiple tiff files and reading the properties of tiff file using c#. TIFF files are one of the format in which images can be saved. To split multipage tiff file, mainly 3 steps are required as 1) Get the total number of pages in a TIFF file 2) Get encoder information for the TIFF type file 3) Save each page of multipage TIFF file into seperate TIFF files. In TIFF, there are predefined types, which tell the value of an item is of which type...</span></span><br />
<span style="text-align: -webkit-auto;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span><br />
<span style="color: #134f5c; text-align: -webkit-auto;"><span style="font-family: Arial, Helvetica, sans-serif;">For more details, please visit my post titled<u> <a href="http://www.blogger.com/goog_1823514841">'</a></u></span></span><span style="text-align: -webkit-auto;"><span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://code.msdn.microsoft.com/Split-multi-page-tiff-file-058050cc"><span style="color: #cc0000;">Split multi page tiff file</span></a><span style="color: #134f5c;"><u>'</u> at MSDN.</span></span></span><br />
<span style="color: #cc0000; font-family: Arial, Helvetica, sans-serif;"><br /></span><a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display: none;">CodeProject</a></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-5619415439454590408?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-59904172779532511772012-05-20T06:18:00.000-07:002012-05-21T06:49:52.114-07:002012-05-21T06:49:52.114-07:00Performance analysis for String and StringBuilder<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Sometimes small-small changes in our code really makes a huge difference to a performance. There are many tips and tricks available and among those, one I am going to discuss over here. I'll be talking about </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">String vs StringBuilder. One needs to be very careful while playing with strings because memory wise there is a huge impact of strings. I </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">know, there are lots and lots of articles available on net on String and StringBuilder, but still I am going to show this, using some statistics.</span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">Here I am taking Fx 4.0 C# console application with different static methods to showcase my analysis. </span><span style="font-family: Arial, Helvetica, sans-serif;">Basically what I am doing here is, I am having a String variable named </span><span style="text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;"><b>outputString </b></span></span><span style="font-family: Arial, Helvetica, sans-serif;">and just looping that for 1000 times and concating the string to variable outputString. </span></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-1WR5nM4fN_s/T7jqcjfxYHI/AAAAAAAAAFA/FZwydWKMJuw/s1600/3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c;"><img border="0" height="107" src="http://3.bp.blogspot.com/-1WR5nM4fN_s/T7jqcjfxYHI/AAAAAAAAAFA/FZwydWKMJuw/s320/3.png" width="320" /></span></a></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Please note, concatenation is done using + symbol. So, what happens internally is, whenever concatenation is done using + symbol, every time, new String object is created. So, as with my snippet. Here I am </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">looping 1000 times, so, it is creating 1000 String objects and every time is is replaced with variable </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">outputString</span><span style="color: #134f5c;"> </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">. Thatway, whenver we use string concatenation with the </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">plus (+) sign, it is definately going to cost our application performance.</span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Well, I guess this much boring theory is enough. Let's move towards statistics. </span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">Here I am using CLR Profiler and is really one of the good tool to analyse our code performance. This tool tells us, how much memory bytes are consumed, </span><span style="font-family: Arial, Helvetica, sans-serif;">Garbage Collector performance and how many objects it is moving to generation Gen0, Gen1 and Gen2 buckets. And at the same time statistics provided by this tool is very easy to understand.</span></span></div>
<div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #134f5c;"><br /></span></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">Ok, I just ran CLR Profiler for the above code and got the below </span><span style="font-family: Arial, Helvetica, sans-serif;">statistics. Here I am not going to cover GC generations in detail, but would like to touch bit on it. One must know that all the objects created in </span><span style="font-family: Arial, Helvetica, sans-serif;">application, first comes to G0 bucket and then older objects are moved to G1 bucket. If the G1 bucket is going to full then older objects get </span><span style="font-family: Arial, Helvetica, sans-serif;">moved to G2 bucket. But for .Net GC, frequency of visiting G1 and G2 is very less, compare to the G0 bucket. It means that GC is visiting bucket 0 frequently, so it </span><span style="font-family: Arial, Helvetica, sans-serif;">is releasing G0 objects much frequently and the scope of object is also very less. So, if your application is creating objects which lot many objects are moving </span><span style="font-family: Arial, Helvetica, sans-serif;">to G1 and G2, then it is not a good sign. </span></span></div>
<div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #134f5c;"><br /></span></span></div>
<div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #134f5c;">Now quickly jumping back to our example:</span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-xespVKQM0kI/T7jrhVcac2I/AAAAAAAAAFI/C6iuUpnrlgM/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c;"><img border="0" height="190" src="http://3.bp.blogspot.com/-xespVKQM0kI/T7jrhVcac2I/AAAAAAAAAFI/C6iuUpnrlgM/s320/1.png" width="320" /></span></a></div>
<div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #134f5c;"><br /></span></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Here we see that heap bytes are present in all three Gen 0,Gen 1,Gen 2 and even the memory wise also it is 7 digit (2,894,353).</span></div>
<div style="text-align: justify;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"> Here Relocated bytes means it is going to be the part of G1 related objects. Here I am not going to analyse all the result, but somehow we are seeing here some negative</span><span style="font-family: Arial, Helvetica, sans-serif;"> signs because few of the objects are falling in G1 and G2 buckets also.</span></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">Now before commenting on it, lets take StringBuilder's data. In this example, </span><span style="font-family: Arial, Helvetica, sans-serif;">I just created a StringBuilder instance named <b>sb</b>. Here I am doing the same thing, but instaed of string, I am taking instance of StringBuilder. In case of </span><span style="font-family: Arial, Helvetica, sans-serif;">StringBuilder</span><span style="font-family: Arial, Helvetica, sans-serif;">, whenever value will be appended, it will not </span><span style="font-family: Arial, Helvetica, sans-serif;">create any new object but just updates the reference of the sb object with the new value. So, internally it is not creating a new object for every </span><span style="font-family: Arial, Helvetica, sans-serif;">concatination. So, this is the real benefit of StringBuilder as compare to Stirng object.</span></span></div>
<div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #134f5c;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/--_Oc7wdtHxI/T7jtnFAMgLI/AAAAAAAAAFQ/EcaLu3Dpu2Q/s1600/4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c;"><img border="0" height="96" src="http://2.bp.blogspot.com/--_Oc7wdtHxI/T7jtnFAMgLI/AAAAAAAAAFQ/EcaLu3Dpu2Q/s320/4.png" width="320" /></span></a></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Although we are looping for 1000 times, but it doesn't mean that we are creating 1000 s</span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">tring objects. That's the way we are controlling memory usage and creation of new objects. Now will run profiler and checkout the results.</span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-RKGvS_rc1M0/T7juBnuvP8I/AAAAAAAAAFY/EPCAP2_M-ZU/s1600/2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c;"><img border="0" height="192" src="http://4.bp.blogspot.com/-RKGvS_rc1M0/T7juBnuvP8I/AAAAAAAAAFY/EPCAP2_M-ZU/s320/2.png" width="320" /></span></a></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">Here we see that memory bytes are reduced to 5 digits (92, 332) and relocated bytes are nothing. If we will see that Heap bytes, it is unknown (0) for all G0, G1 and </span><span style="font-family: Arial, Helvetica, sans-serif;">G2. </span><span style="font-family: Arial, Helvetica, sans-serif;">It means, none of the objects are moved to G1 and G2. All the objects are created in G0 and release from G0 itself.</span></span></div>
<div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #134f5c;"><br /></span></span></div>
<div style="text-align: justify;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #134f5c;"><br /></span></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">So, here we noticed that there is a significant difference in both memory usage as well as GC's bucket movements.</span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">So, here we can conclude that we should prefer to use StringBuilder, rather than String specially when we are dealing with concatenations. </span></div>
</div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-5990417277953251177?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-25784096693299087172012-05-18T22:06:00.000-07:002012-05-18T22:07:48.085-07:002012-05-18T22:07:48.085-07:00BackgroundWorker in .Net Console Application<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Today I was just doing net surf and came across one interesting question 'Can progress event of BackgroundWorker execute after completed event'. At first I thought no, but when I tried this with Console application, I was also able to reproduce this issue. Now question is, how come this scenario occurs in Console app and not in Windows form. Pretty interesting, right ?</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Now coming to Windows form, this issue will never occur, due to message queuing support. Windows message queue takes very good care of execution sequence of the events. This clearly mean that the progress event may run after the DoWork has completed, but the completion event will always happen afterwards. Another interesting thing here is the SynchronizationContext, which helps in maintaining all these sequencing.</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">But when talking about Console application, none of the above holds true. There is no SynchronizationContext installed and the events just end up in getting run in threadpool thread, which doesn't guarantee any order.</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Test case: I created a console app and used Backgroundworker with all the required event handlers. In progress event handler, I added below lines:</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Console.WriteLine("One");</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Console.WriteLine("Two");</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Console.WriteLine("Three");</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Console.WriteLine("Four");</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">On executing the console application, I found that output messages are not in the order, which I mentioned in code. On standard output I received Two, Three, Four, One and sometimes I received One, Two, Three, Four and sometime, I also found one of the message missing and in output I got only Two, Three, Four. But in Windows Form, I always get the output in correct order as One, Two, Three, Four.</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">I hope, above analogy makes sense.</span></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-2578409669329908717?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-56598517687560091252012-05-18T06:29:00.001-07:002012-05-26T23:46:52.552-07:002012-05-26T23:46:52.552-07:00Resource name can not be used more than once<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Recently I came across an error "Resource name can not be used more then once". Apart from this, error message was not showing any other information, not even line number, file name, nothing. Generally such errors came, when there is any duplicate key present in resource file, but in my case, I was not using any resource file also. So, there is no chance of duplicate keys also. I tried to hit my head many times for some online help, but no luck :(</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">One thing I noticed was, after building my solution (it was in VS2010) for 3-4 times continuously, error was thrown. Please note, I was just building the solution, without doing any modification in my code or in any of the files. Still I didn't get any clue.</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">So, finally I thought to remove one one project from my solution and build. Till 4-5 projects I removed and I didn't get any clue till yet. Suddenly I found that, Obj folder is added to my solution explorer. This obj folder holds all temporary files with few .resource files. Then I realize that, entire issue was due to this Obj folder, because whenever we build our solution, Visual Studio tries to create some files, and in my case these files were already part of that Obj folder.</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Till now also, I am not sure, how that Obj folder get added to my solution explorer. Probably by mistake, I might have clicked on "include in project", as "Show all files" option was also enabled.</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">But finally, I was able to figure out the cause and thought to share it here. </span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Hope it will help you !!!</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<br /><a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display:none" >CodeProject</a></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-5659851768756009125?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-29413815127618992292012-05-12T04:37:00.000-07:002012-05-26T23:47:09.598-07:002012-05-26T23:47:09.598-07:00Matching braces in code<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">In day-to-day life developers use to write huge logic involving many braces ({,}) in the code. Reaching to end/start of any condition gets complex as the lines of code increases. To simplify the same, one can use key combination of Ctrl+].</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">To use the given key combination, place the cursor on any brace and hit Ctrl+]. If the brace is an end brace, the control will move to the matching brace i.e. start brace of the condition and vice versa.</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Also the same key combination can be used to navigate to the matching comment (/*, */) or region (#region). In these cases, the cursor position should be on the comment or the region respectively.</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Hope this helps !!!</span><a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display:none" >CodeProject</a></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-2941381512761899229?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-25697051367458630262012-04-25T07:57:00.001-07:002012-04-25T07:57:08.996-07:002012-04-25T07:57:08.996-07:00How throw works in .Net<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">As we all know, Exception handling plays a very important
role in any developer’s life. When talking about exception handling, throw is
the first thing, which comes into our mind. Today, we will see, how actually
throw works.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-lxZWhM2B0lU/T5gKKXHnHoI/AAAAAAAAAEY/1GW14hh__ck/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="293" src="http://2.bp.blogspot.com/-lxZWhM2B0lU/T5gKKXHnHoI/AAAAAAAAAEY/1GW14hh__ck/s400/1.png" width="400" /></span></a></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">The given code catches the exception and just throws it again,
without passing any explicit Exception object. </span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Now, let’s take another version of
this above code:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-vvAc7e-icu0/T5gKN0C0wsI/AAAAAAAAAEg/wcpObeEnkxc/s1600/2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="292" src="http://3.bp.blogspot.com/-vvAc7e-icu0/T5gKN0C0wsI/AAAAAAAAAEg/wcpObeEnkxc/s400/2.png" width="400" /></span></a></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">This given code will create the object of Employee and will
catch the exception and from catch block it will throw the catched exception via
ex (our Exception class object).</span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Now question is how these two code snippets are different.
For more analysis, let’s open ILDasm and drop your .EXE into it. For the first
snippet, we will see something like below:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-cZn6kJYW2KU/T5gKOsCpglI/AAAAAAAAAEo/LqsKmqpwLQ8/s1600/3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="248" src="http://3.bp.blogspot.com/-cZn6kJYW2KU/T5gKOsCpglI/AAAAAAAAAEo/LqsKmqpwLQ8/s400/3.png" width="400" /></span></a></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">From this given image, we can see ex (Exception class object) has
been defined as local variable using .local, but in the catch block, compiler changes
the throw statement into <b>rethrow</b>. It
means, instead of changing the original stack trace, compiler is just
re-throwing the existing one.</span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Whereas, if we will look at second snippet:</span></span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-2cB-QFrWaQM/T5gKQqlQsYI/AAAAAAAAAEw/bpRNDOfP4cE/s1600/4.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="278" src="http://3.bp.blogspot.com/-2cB-QFrWaQM/T5gKQqlQsYI/AAAAAAAAAEw/bpRNDOfP4cE/s400/4.png" width="400" /></span></a></div>
<div class="MsoNormal">
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Here also ex is defined as a local variable, but catch block
is bit different here as compared to snippet 1.
In the catch block, compiler is loading data from location 1 (ldloc 1),
which is ex (Exception object) and throws that one. And as a result, this ex
will not hold all the stack trace raised earlier except the stack trace from
this current state.</span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">So, it is clear that ex override the stack trace whereas,
just throw statement does not override the stack trace.</span></div>
<br />
<br /></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-2569705136745863026?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-11314196668779496642012-04-23T07:20:00.000-07:002012-05-26T23:47:41.791-07:002012-05-26T23:47:41.791-07:00Finalize in .Net<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">We implement the Finalize method to release the unmanaged resources. First let’s see, what is managed and unmanaged resources. Managed ones are those, which we write in .Net languages. But when we write code in any non .Net language like VB 6 or any windows API, we call it as unmanaged. And there are very high chances that we use any win API or any COM component in our application. So, as managed resources are not managed by CLR, we need to handle them at our own. So, once we are done with unmanaged resources, we need to clean them. The cleanup and releasing of unmanaged is done in Finalize(). If your class is not using any unmanaged resources, then you can forget about Finalize(). But problem is, we can’t directly call Finalize(), we do not have control of it. Then who is going to call this. Basically GC calls this.</span><br />
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">And one more thing to remember is, there is no Finalize keyword that we will write and implement it. We can define Finalize by defining the Destructor. Destructor is use to clean up unmanaged resourced. When u will put ~ sign in front of class name, it will be treated as destructor. So, when code is compiled, the destructor is going to convert that into Finalize and further garbage collector will add it to the Finalize queue. Let’s take this sample code:</span><br />
<div>
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">class A </span><span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> public A()</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> { Console.WriteLine("I am in A"); }</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> ~A()</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> { Console.WriteLine("Destructor of A"); }</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> class B : A </span><span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> public B()</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> { Console.WriteLine("I am in B"); }</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> ~B()</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> { Console.WriteLine("Destructor of B"); }</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> class C : B </span><span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> public C()</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> { Console.WriteLine("I am in C"); }</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> ~C()</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> { Console.WriteLine("Destructor of C"); }</span></div>
<div>
<span style="color: orange; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span></div>
</div>
<div>
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">Now using Reflector, we will see,
if Destructor, really converted to Finalize:</span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-DXwDpaeshcE/T5OLYTc-whI/AAAAAAAAAEQ/g4hBoM2Skys/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><img border="0" src="http://1.bp.blogspot.com/-DXwDpaeshcE/T5OLYTc-whI/AAAAAAAAAEQ/g4hBoM2Skys/s1600/1.png" /></span></a></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
</div>
<div class="MsoNormal">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">And WOW, it’s really done. Here
we can see that there is nothing like destructor. Basically destructor is
overriding the Finalize method.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">Hope it helps !!!</span></div>
</div>
<br />
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><object height="0" id="skype_plugin_object" location.hostname="www.blogger.com" location.href="http://www.blogger.com/blogger.g?blogID=2254111756987838850#editor" style="left: -100px; position: absolute; top: -100px; visibility: hidden;" type="application/x-vnd.skype.click2call.chrome.5.6.0" width="0"></object><object height="0" id="skype_plugin_object" location.hostname="www.blogger.com" location.href="http://www.blogger.com/blogger.g?blogID=2254111756987838850#editor" style="left: -100px; position: absolute; top: -100px; visibility: hidden;" type="application/x-vnd.skype.click2call.chrome.5.6.0" width="0"></object></span><a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display:none" >CodeProject</a></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-1131419666877949664?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-89963228252243469852012-04-21T20:31:00.001-07:002012-05-26T23:48:12.293-07:002012-05-26T23:48:12.293-07:00Memory Leak Analysis for .Net application<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">Memory
leaks in .Net applications are always proven to be the nightmare for
developers. Many times we get “OutOfMemoryException”, which is nothing but due
to memory leak only. There are many reasons, which lead to memory leak
situation. For example, sometimes we forget to release unmanaged resources,
dispose heavy objects (i.e., drawing objects), even holding reference of
managed objects, longer than necessary can also lead to memory leaks.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoBodyText" style="text-align: justify;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">So, if the application
is small, one can analyze the code and figure it out, which object is causing
memory leak. But when it comes to a large application, it is not at all
possible to figure out manually. In that case, we need some tool, which can
help us to figure out the area or object, which is causing memory leak. So,
today I surf internet and came up with a tool called .Net Memory Profiler,
which can do analysis for us and give us the statistics of all the instances.</span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">Ok,
instead of getting more into theory, let’s jump quickly to the demo. I have a
windows form application named “MemoryLeakAnalysis”. Now I open memory
profiler, which comes up with the below screen. Profiler can be run in two
different modes as interactive (normal mode with UI shown below) and
non-interactive mode (can only be used for automated testing as part of script.
It will not show any window).<o:p></o:p></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://1.bp.blogspot.com/-brDTmf2c9eo/T5N3rU0dqKI/AAAAAAAAADI/v_EhpnOCQOQ/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="237" src="http://1.bp.blogspot.com/-brDTmf2c9eo/T5N3rU0dqKI/AAAAAAAAADI/v_EhpnOCQOQ/s320/1.png" width="320" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">Click
on ‘Profile application’ and select the exe of your application, as shown
below. If require, command line argument can also be provided<o:p></o:p></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://1.bp.blogspot.com/-VVWZNCVWfxM/T5N4Cf9bIzI/AAAAAAAAADQ/ox03oJsx3UQ/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="275" src="http://1.bp.blogspot.com/-VVWZNCVWfxM/T5N4Cf9bIzI/AAAAAAAAADQ/ox03oJsx3UQ/s320/1.png" width="320" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">On
click of next, you can decide the profiling level as Very low, Low, Medium,
High, etc. Moving further, you can also decide, whether you want to enable
unmanaged resource tracker (collects information about handles, GDI handles,
etc), and finally click on start. Clicking on start will launch your
application (here my application name is Test Leakage)<o:p></o:p></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://1.bp.blogspot.com/-JlVjBNO14FU/T5N4TG5FWFI/AAAAAAAAADY/oJ9G8ldlBKc/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="228" src="http://1.bp.blogspot.com/-JlVjBNO14FU/T5N4TG5FWFI/AAAAAAAAADY/oJ9G8ldlBKc/s320/1.png" width="320" /></span></a></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">In the right
hand side, you can see various options as Collect snapshot, Stop profiling,
Show real-time data. And just below that, we have ‘Investigate memory leaks’.
On clicking of ‘Investigate memory leaks’, you will get the list of major
steps, which needs to be taken up, in order to analyze leakage.</span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-uAjz7Y6-MnU/T5N4lAcqlpI/AAAAAAAAADg/c3ii8hEt7ac/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="320" src="http://3.bp.blogspot.com/-uAjz7Y6-MnU/T5N4lAcqlpI/AAAAAAAAADg/c3ii8hEt7ac/s320/1.png" width="225" /></span></a></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<br />
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<br />
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<br />
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span lang="EN-US"><span lang="EN-US"></span></span></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">Now
the actual investigation starts.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US">1) </span><span lang="EN-US">Perform
initial operation - </span>Perform
the operation you suspect is memory leaking (e.g., open a document, work with
it and then close it). Performing an initial operation will make sure that
instances that are only created once are not included in the memory leak
investigation. In my case, I’ll click on ‘Start Memory Leak’ button and after a
while, I’ll click on ‘Stop Memory Leak’</span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US">2) </span><span lang="EN-US">Collect
base snapshot - </span>The
base snapshot will be used as a reference when looking for unexpected new
instances that are created by the operation. Once the snapshot is taken, we will
come up with below screen, with some statistics.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-bB1cmgkbLe8/T5N43KOfoII/AAAAAAAAADo/-eMp1MA5hy0/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="210" src="http://3.bp.blogspot.com/-bB1cmgkbLe8/T5N43KOfoII/AAAAAAAAADo/-eMp1MA5hy0/s320/1.png" width="320" /></span></a></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span lang="EN-US" style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="text-indent: -18pt;">3) </span><span lang="EN-US" style="text-indent: -18pt;">Perform
operation again - </span>Again
we will perform the operation, which we suspect are leaking memory. Because,
this operation will give us new snapshot for comparison. In my application, I
will again click on ‘start Memory Leak’ button:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-8KsyVBphE6g/T5N5Yg03MWI/AAAAAAAAADw/gbZARP0wuRE/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><img border="0" src="http://4.bp.blogspot.com/-8KsyVBphE6g/T5N5Yg03MWI/AAAAAAAAADw/gbZARP0wuRE/s1600/1.png" /></span></a></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 18pt;">
</div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US">4) </span><span lang="EN-US">Collect
primary snapshot - </span>The
primary snapshot will be used when investigating new instances that might be
part of memory leak.</span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US">5) </span><span lang="EN-US">Identify
the types with New instances - </span>Instances
shown under Overview tab (highlighted one), are the one’s, which are not
garbage collected.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-c90Egq-inl8/T5N5sjkbBMI/AAAAAAAAAD4/9zN7zHGHwaw/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="102" src="http://2.bp.blogspot.com/-c90Egq-inl8/T5N5sjkbBMI/AAAAAAAAAD4/9zN7zHGHwaw/s320/1.png" width="320" /></span></a></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span lang="EN-US" style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span lang="EN-US" style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span lang="EN-US" style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="text-indent: -18pt;">6) </span><span lang="EN-US" style="text-indent: -18pt;">Identify
the types which are not expected to have New instances - </span><span style="text-indent: -18pt;">For
those instances, we will find that value of New column is 0, which clearly
states that that object is already collected by GC.</span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="text-indent: -18pt;">7) </span><span lang="EN-US" style="text-indent: -18pt;">Investigate
root path - </span><span style="text-indent: -18pt;">Root
path can be extremely useful for identifying memory leaks. Shortest path
provide information about why instances are not garbage collected. You can use
browse buttons to locate a root path that you’d like to investigate further</span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-ms9zduWrGBM/T5N6JTUU-9I/AAAAAAAAAEA/NpNb44fzT1g/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="162" src="http://2.bp.blogspot.com/-ms9zduWrGBM/T5N6JTUU-9I/AAAAAAAAAEA/NpNb44fzT1g/s320/1.png" width="320" /></span></a></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span lang="EN-US" style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="text-indent: -18pt;">8) </span><span lang="EN-US" style="text-indent: -18pt;">Determine
whether root path instance is part of memory leak - </span><span style="text-indent: -18pt;">Instance
graph and Allocation call stack will provide information about how the instance
is used, why it has not been garbage collected, and how it was created. This
information can be used to determine, whether instance is part of memory leak
or not</span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-6_5FWklgsl8/T5N6hD5LulI/AAAAAAAAAEI/hHiU4nyyb1M/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="175" src="http://3.bp.blogspot.com/-6_5FWklgsl8/T5N6hD5LulI/AAAAAAAAAEI/hHiU4nyyb1M/s320/1.png" width="320" /></span></a></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span lang="EN-US" style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="text-indent: -18pt;">9) </span><span lang="EN-US" style="text-indent: -18pt;">Steps
from 6 to 8 can be used to analyze another types.</span></span></div>
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;">So,
by looking at the instance graph and red arrows shown above, will help us the
identify, where exactly leak is happening.<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="margin-left: 36pt; text-indent: -18pt;">
<span style="text-indent: -18pt;"><span style="color: #45818e; font-family: Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal" style="font-family: 'Times New Roman', serif; font-size: 12pt; margin-left: 36pt; text-indent: -18pt;">
<span style="font-family: Arial, sans-serif; font-size: 9pt; text-indent: -18pt;"><br /></span><a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display:none" >CodeProject</a></div>
<br />
<br /></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-8996322825224346985?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-90845709939716541982012-03-31T22:04:00.000-07:002012-05-26T23:48:30.824-07:002012-05-26T23:48:30.824-07:00Computer performance & Clock speed<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div style="text-align: justify;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Many people use clock speed as a measure of a computer’s total computing power, but that term can be very misleading for a couple of reasons.</span></div><br />
<div style="text-align: justify;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">The computer keeps all its devices synchronized by using its clock. This isn’t a regular clock—it’s a “clock in a chip,” which keeps highly accurate time and ticks much more rapidly than a wall clock. The faster the computer’s clock ticks, the more quickly the device can move on to a new task. The central processing unit needs a certain number of clock ticks to execute each of its instructions. Therefore, the faster the clock ticks (that is, the “clock speed”), the more instructions the CPU can execute per second.</span></div><br />
<div style="text-align: justify;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"> However, that’s not the end of the story. Different processors use different instruction sets, each of which can require a different number of ticks. That means different kinds of processors may execute different numbers of instructions per second, even if they have the same clock speed. You can use clock rate to compare two of the same kinds of processor (for example, a 2.93-gigahertz (GHz) Intel Pentium 4 and a 3.0-GHz Intel Pentium 4) but not as an accurate comparison between two processors of different types (for example, a 3.0-GHz Intel Pentium 4 and a 3.0-GHz AMD Athlon II).</span></div><div style="text-align: justify;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div style="text-align: justify;"></div><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Even if you could fgure out which processor executes more instructions per second, that figure alone doesn’t necessarily tell you which computer will be faster for your program. Many programs - most, in fact—are limited by factors other than sheer processor speed, including amount and speed of memory, disk space, network speed, graphics or floating-point processor speeds, and bus speed.</span><br />
<br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Many modern computers have multiple processors or multiple cores (execution areas within a processor), so they can perform more than one task at the same time. Whether the computer gets a significant beneft from multiple cores depends on whether the tasks it is performing can be easily split into separate pieces—and whether the program was written to take advantage of multi-core hardware. Many programs are limited by disk drive speed. Disk drives spin at anywhere from 3,000 RPM to 15,000 RPM (speeds between 4,200 RPM and 7,200 RPM are most typical), so the time it takes to read and write data can vary dramatically.</span><br />
<br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Which of these factors is most important for your application depends on what that application does. If your program uses a local database heavily, disk speed will be a big factor. If the database is on a remote server, then the speed of the server and the network’s speed are probably bigger performance factors for your application than the speed of your local CPU.</span><br />
<br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">To get an idea of how well the program will run ahead of time, focus on the system’s overall performance, running a wide variety of tests rather than looking just at clock speed. To look at one set of tests in the most recent versions of Microsoft Windows, open the computer’s Start menu, right-click the Computer entry, and select Properties to see the basic information display shown in Figure:</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-DPuHuQ5mo3s/T3ff4HqnZSI/AAAAAAAAAC0/InA6k42ntKw/s1600/s.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="227" src="http://3.bp.blogspot.com/-DPuHuQ5mo3s/T3ff4HqnZSI/AAAAAAAAAC0/InA6k42ntKw/s320/s.png" width="320" /></span></a></div><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">To get more detail, click the Windows Experience Index link to see the display shown in Figure below. </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">This display shows performance scores for several different system features.</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-Nz-LqlPhALk/T3fgR2lWXSI/AAAAAAAAAC8/fk26xZkyBy0/s1600/s1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="180" src="http://4.bp.blogspot.com/-Nz-LqlPhALk/T3fgR2lWXSI/AAAAAAAAAC8/fk26xZkyBy0/s320/s1.png" width="320" /></span></a></div><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">By given figure, we can see that the graphics scores are the lowest, so this system may </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">not give the best performance for high-end graphics programs, such as three-dimensional games. </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">But the processor, RAM, and disk scores are higher, so this computer may </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">be just fine for applications that are not graphics-intensive.</span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">The Windows Experience Index still doesn’t consider your program’s particular needs. For example, </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">it doesn’t know what kinds of instructions your program will perform the most (such as integer cal</span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">culations, foating-point calculations, string operations, and so on) and it doesn’t consider network </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">bandwidth, but at least it provides a reasonably consistent value that can help you compare different </span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">systems.</span><br />
<br />
<br />
<br />
<br />
<br /><a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display:none" >CodeProject</a>
</div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-9084570993971654198?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com2tag:blogger.com,1999:blog-2254111756987838850.post-27323716343436215112012-03-30T06:19:00.000-07:002012-05-26T23:48:50.588-07:002012-05-26T23:48:50.588-07:00Laptops vs Notebooks vs Netbooks vs Tablets<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">A laptop is a computer that is intended to run anywhere as it is portable. Laptops have integrated screens and keyboards and run on batteries. Heavy use to some hardware such as GPU, DVD drives can quickly drain the batteries. Laptops have a touchpad, pointing stick, trackball, or other pointing device. Nowadays, we can add external devices like mouse, keyboard etc.</span></div><div class="MsoNormal"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="MsoNormal"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Notebooks are stripped-down laptops. They are thin and have relatively small screens and are ultra-light. They rarely have CD-ROM or DVD and also have very limited graphics capabilities. As notebooks doesn’t have external media (DVD, etc), they typically have integrated network connection hardware so one can load software on to them. Network hardware can be used to access the internet.</span></div><div class="MsoNormal"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="MsoNormal"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Netbooks are even more stripped down than notebooks. They typically have less powerful processors and are primarily used for networked applications as web browsers, where most of the processing happens on a remote server.</span></div><div class="MsoNormal"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div class="MsoNormal"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">A tablet is similar to laptop that uses touch screen or stylus as its primary input device. Tablets may display virtual keyboards on their screens and may use handwriting recognition for text input.Lap</span></div><a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display:none" >CodeProject</a></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-2732371634343621511?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-10452499669891144632012-03-04T04:57:00.000-08:002012-05-26T23:49:16.625-07:002012-05-26T23:49:16.625-07:00WPF: Significance of x:Key attribute<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US">Each object declared as resource must set </span><span lang="EN-US" style="color: red; font-size: 10pt;">x</span><span lang="EN-US" style="color: blue; font-size: 10pt;">:</span><span lang="EN-US" style="color: red; font-size: 10pt;">Key</span><span lang="EN-US"> property. This property will be used by another elements to access the resource. But for Style objects, there is an exception. Style objects that set the </span><span lang="EN-US" style="color: red; font-size: 10pt;">TargetType</span><span lang="EN-US"> property do not need to set </span><span lang="EN-US" style="color: red; font-size: 10pt;">x</span><span lang="EN-US" style="color: blue; font-size: 10pt;">:</span><span lang="EN-US" style="color: red; font-size: 10pt;">Key</span><span lang="EN-US"> explicitly because it is set implicitly behind the scenes. </span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US"><br />
</span></span></div><div class="MsoNormal"><b><u><span lang="EN-US"><span style="font-family: Arial, Helvetica, sans-serif;">Scenario1: When x:Key is defined<o:p></o:p></span></span></u></b></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: blue; font-size: 10pt;"><</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Style</span><span lang="EN-US" style="color: red; font-size: 10pt;"> x</span><span lang="EN-US" style="color: blue; font-size: 10pt;">:</span><span lang="EN-US" style="color: red; font-size: 10pt;">Key</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="myStyle"</span><span lang="EN-US" style="color: red; font-size: 10pt;"> TargetType</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="Button"><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: #a31515; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-size: 10pt;"><</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Setter</span><span lang="EN-US" style="color: red; font-size: 10pt;"> Property</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="Background"</span><span lang="EN-US" style="color: red; font-size: 10pt;"> Value</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="Yellow"/><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: blue; font-size: 10pt;"></</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Style</span><span lang="EN-US" style="color: blue; font-size: 10pt;">><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US">In above example, </span><span lang="EN-US" style="color: red; font-size: 10pt;">x</span><span lang="EN-US" style="color: blue; font-size: 10pt;">:</span><span lang="EN-US" style="color: red; font-size: 10pt;">Key</span><span lang="EN-US"> property is used, so, style will be visible on Button, only when Style property is used explicitly on element, as shown in below snippet:</span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: blue; font-size: 10pt;"><</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Button</span><span lang="EN-US" style="color: red; font-size: 10pt;"> <b>Style</b></span><span lang="EN-US" style="color: blue; font-size: 10pt;">="{</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">StaticResource</span><span lang="EN-US" style="color: red; font-size: 10pt;"> myStyle</span><span lang="EN-US" style="color: blue; font-size: 10pt;">}"</span><span lang="EN-US" style="color: red; font-size: 10pt;"> Width</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="60" </span><span lang="EN-US" style="color: red; font-size: 10pt;">Height</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="30" /><o:p></o:p></span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b><u><span lang="EN-US"><span style="font-family: Arial, Helvetica, sans-serif;">Scenario2:<o:p></o:p></span></span></u></b><b><u><span lang="EN-US"><span style="font-family: Arial, Helvetica, sans-serif;">When x:Key is not defined</span></span></u></b></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: blue; font-size: 10pt;"><</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Style</span><span lang="EN-US" style="color: red; font-size: 10pt;"> TargetType</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="Button"><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: #a31515; font-size: 10pt;"> </span><span lang="EN-US" style="color: blue; font-size: 10pt;"><</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Setter</span><span lang="EN-US" style="color: red; font-size: 10pt;"> Property</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="Background"</span><span lang="EN-US" style="color: red; font-size: 10pt;"> Value</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="Yellow"/><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: blue; font-size: 10pt;"></</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Style</span><span lang="EN-US" style="color: blue; font-size: 10pt;">><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US">In above example, style will be applied by default on all the buttons (due to </span><span lang="EN-US" style="color: red; font-size: 10pt;">TargetType</span><span lang="EN-US">) as no </span><span lang="EN-US" style="color: red; font-size: 10pt;">x</span><span lang="EN-US" style="color: blue; font-size: 10pt;">:</span><span lang="EN-US" style="color: red; font-size: 10pt;">Key</span><span lang="EN-US"> is defined in Style resource. Code for the button is shown below:</span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: blue; font-size: 10pt;"><</span><span lang="EN-US" style="color: #a31515; font-size: 10pt;">Button</span><span lang="EN-US" style="color: red; font-size: 10pt;"> Name</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="btnShow"</span><span lang="EN-US" style="color: red; font-size: 10pt;"> Width</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="60"</span><span lang="EN-US" style="color: red; font-size: 10pt;"> Height</span><span lang="EN-US" style="color: blue; font-size: 10pt;">="30" /></span></span></div><a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display:none" >CodeProject</a></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-1045249966989114463?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-90263084638720834342012-03-03T04:58:00.000-08:002012-05-26T23:49:38.304-07:002012-05-26T23:49:38.304-07:00WPF: StaticResource vs DynamicResource<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div class="MsoNormal"><span lang="EN-US"><span style="font-family: Arial, Helvetica, sans-serif;">Logical resources allow you to define objects in XAML, which are not part of visual tree but can be used in your user interface. One of the examples of logical resource is Brush, which is used to provide a color scheme. Generally those objects are defined as resource, which are used by multiple elements of the applications.</span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: blue;"> <</span><span lang="EN-US" style="color: #a31515;">Window.Resources</span><span lang="EN-US" style="color: blue;">><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: #a31515;"> </span><span lang="EN-US" style="color: blue;"><</span><span lang="EN-US" style="color: #a31515;">RadialGradientBrush</span><span lang="EN-US" style="color: red;"> x</span><span lang="EN-US" style="color: blue;">:</span><span lang="EN-US" style="color: red;">Key</span><span lang="EN-US" style="color: blue;">="myGradientBrush"><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: #a31515;"> </span><span lang="EN-US" style="color: blue;"><</span><span lang="EN-US" style="color: #a31515;">GradientStop</span><span lang="EN-US" style="color: red;"> Color</span><span lang="EN-US" style="color: blue;">="Green"</span><span lang="EN-US" style="color: red;"> Offset</span><span lang="EN-US" style="color: blue;">="0"/><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: #a31515;"> </span><span lang="EN-US" style="color: blue;"><</span><span lang="EN-US" style="color: #a31515;">GradientStop</span><span lang="EN-US" style="color: red;"> Color</span><span lang="EN-US" style="color: blue;">="Blue"</span><span lang="EN-US" style="color: red;"> Offset</span><span lang="EN-US" style="color: blue;">="2"/><o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: #a31515;"> </span><span lang="EN-US" style="color: blue;"></</span><span lang="EN-US" style="color: #a31515;">RadialGradientBrush</span><span lang="EN-US" style="color: blue;">></span><span lang="EN-US" style="color: #a31515;"> <o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: #a31515;"> </span><span lang="EN-US" style="color: blue;"></</span><span lang="EN-US" style="color: #a31515;">Window.Resources</span><span lang="EN-US" style="color: blue;">><o:p></o:p></span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span lang="EN-US"><span style="font-family: Arial, Helvetica, sans-serif;">Now, above declared resource could be used as either static or dynamic resource. One point to remember is that, when using static resources, it should be first defined in XAML code, before it can be referred. Static and Dynamic resources can be used as:</span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: blue;"><</span><span lang="EN-US" style="color: #a31515;">Grid</span><span lang="EN-US" style="color: red;"> Background</span><span lang="EN-US" style="color: blue;">="{</span><span lang="EN-US" style="color: #a31515;">StaticResource</span><span lang="EN-US" style="color: red;"> myGradientBrush</span><span lang="EN-US" style="color: blue;">}"></span></span><span lang="EN-US" style="color: blue; font-family: Arial, Helvetica, sans-serif;"><</span><span lang="EN-US" style="color: #a31515; font-family: Arial, Helvetica, sans-serif;">/Grid</span><span lang="EN-US" style="color: blue; font-family: Arial, Helvetica, sans-serif;">></span></div><div class="MsoNormal"><span lang="EN-US" style="color: blue;"><span style="font-family: Arial, Helvetica, sans-serif;">or<o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: blue;"><</span><span lang="EN-US" style="color: #a31515;">Grid</span><span lang="EN-US" style="color: red;"> Background</span><span lang="EN-US" style="color: blue;">="{</span><span lang="EN-US" style="color: #a31515;">DynamicResource </span><span lang="EN-US" style="color: red;">myGradientBrush</span><span lang="EN-US" style="color: blue;">}"><</span></span><span lang="EN-US" style="color: blue; font-family: Arial, Helvetica, sans-serif;">/</span><span lang="EN-US" style="color: #a31515; font-family: Arial, Helvetica, sans-serif;">Grid</span><span lang="EN-US" style="color: blue; font-family: Arial, Helvetica, sans-serif;">></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US">The difference</span><span lang="EN-US" style="color: blue;"> </span><span lang="EN-US">between</span><span lang="EN-US" style="color: blue;"> StaticResource and DynamicResource </span><span lang="EN-US">lies in how the resources are retrieved by the referencing elements. </span><span lang="EN-US" style="color: blue;">StaticResource </span><span lang="EN-US">are retrieved only once by the referencing element and used for entire life of the resource. On the other hand, </span><span lang="EN-US" style="color: blue;">DynamicResource </span><span lang="EN-US">are acquired every time the referenced object is used.</span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US">Putting it in simpler way, if the color property of </span><span lang="EN-US" style="color: #a31515;">RadialGradientBrush</span><span lang="EN-US"> is changed in code to Orange and Pink, then it will reflect on elements only when resource is used as </span><span lang="EN-US" style="color: blue;">DynamicResource</span><span lang="EN-US">. Below is the code to change the resource in code: </span></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: #2b91af;">RadialGradientBrush</span><span lang="EN-US"> radialGradientBrush = <span style="color: blue;">new</span> <span style="color: #2b91af;">RadialGradientBrush</span>( <span style="color: #2b91af;">Colors</span>.Orange, <span style="color: #2b91af;">Colors</span>.Pink);<o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: Arial, Helvetica, sans-serif;"><span lang="EN-US" style="color: blue;">this</span><span lang="EN-US">.Resources[<span style="color: #a31515;">"myGradientBrush"</span>] = radialGradientBrush;<o:p></o:p></span></span></div><div class="MsoNormal"><br />
</div><span lang="EN-US"><span style="font-family: Arial, Helvetica, sans-serif;">The demerit of <span style="color: blue;">DynamicResource </span>is that it reduces application performance because resources are retrieved every time they are used. The best practice is to <span style="color: blue;">StaticResource </span>use until there is a specific reason to use <span style="color: blue;">DynamicResource.</span></span></span><a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display:none" >CodeProject</a></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-9026308463872083434?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com4tag:blogger.com,1999:blog-2254111756987838850.post-41249761053886785572011-12-31T20:18:00.000-08:002011-12-31T20:47:09.651-08:002011-12-31T20:47:09.651-08:00Problem with Primary key as an Integer<div dir="ltr" style="text-align: left;" trbidi="on"><span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: #134f5c;">We all know that any good database design has a unique primary key. Now point is how to decide, whether our primary key should be integer or not ? Well, primary key as an Integer works well with local systems and easy to use and also works great while writing manual SQL statements. But what if one is not working on local system and working in a distributed environment where one has to deal with replication scenarios. In such scenarios, Integers can't be primary key as they have state (sequencing) and can become a major security threat. Now here system demand for something unique apart from integers. And here comes GUID into picture, which provides globally unique id. You might be thinking that, is it a good choice to use 16 bytes of primary key instead of 4 bytes, then my answer will be definitely YES only when sync'ing is required. Using GUID as a row identity feels more truely unique and databse guru </span><a href="http://groups.google.com/group/microsoft.public.sqlserver.programming/msg/6d61dbf80d6f0fb6?hl=en&lr=&ie=UTF-8&oe=UTF-8&rnum=14"><span style="color: red;">Joe </span></a><span style="color: #134f5c;">seems to agree. But again performance issues arises in various scenarios. Just wait a while for my next post on more performance impacts</span></span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Advantages of using GUID:</span><br />
<br />
<ul style="text-align: left;"><li><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Unique across every server, every database, every table </span></li>
<li><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">GUID's can be generated from anywhere, without doing round trip to database</span></li>
<li><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Provides easy merging and distribution of databases among multiple servers</span></li>
</ul></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-4124976105388678557?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-91131075181964854502011-11-24T09:21:00.001-08:002011-11-24T09:21:32.696-08:002011-11-24T09:21:32.696-08:00Finally I'm back to blogging world<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">Oh, finally I am back. First I would like to apologize for the lack of recent posts. As finally I am settled, soon I'll again start posting in a week or two.</span></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-9113107518196485450?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-37581722367196837452011-06-05T00:12:00.000-07:002012-05-23T11:07:18.832-07:002012-05-23T11:07:18.832-07:00Reducing flicker, blinking in DataGridView<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">One of my project requirement was to create a Output Window similar to Visual Studio. For that I used a DataGridView. But when I start my application , I found that there is lot of blinking, flicker, pulling...</span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">After badly hitting my head with google, I found a very easy way. We just need to create a extension method to DataGridView and it's all done:</span><br />
<br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">public static void DoubleBuffered(this DataGridView dgv, bool setting) </span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">{ </span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"> Type dgvType = dgv.GetType(); </span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"> PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", </span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"> BindingFlags.Instance | BindingFlags.NonPublic); </span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"> pi.SetValue(dgv, setting, null); </span><br />
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">}</span>
<a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display:none">CodeProject</a>
</div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-3758172236719683745?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-84859156463839332122011-05-14T07:03:00.000-07:002012-05-23T11:06:08.787-07:002012-05-23T11:06:08.787-07:00Overview of CDN<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin: 0in 0in 10pt; text-align: justify;">
<b style="mso-bidi-font-weight: normal;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">CDN (Content Delivery Network)</span></b></div>
<ul style="text-align: left;">
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l4 level1 lfo1; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">A computer network which has multiple copies of data stored at different points of the network.</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l4 level1 lfo1; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c; font-family: Arial;"> </span><span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">The end user connected to a CDN will access the data from the nearest server (middle) instead of connecting to a Central server.</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l4 level1 lfo1; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c; font-family: Arial;"> </span><span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">Few of the applications include media distribution, multiplayer gaming, and distance learning.</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l4 level1 lfo1; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c; font-family: Arial;"> </span><span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">The end user can be a wired or wireless unit, which tries to access the content.</span></span></div>
</li>
</ul>
<div class="MsoNormal" style="margin: 0in 0in 10pt; text-align: justify;">
<span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">The middle servers (or several servers forming a cluster) store the images of the content from the central (main) server. They are located at the edge of the ISP network and may be geographically separated from each other. </span></div>
<h1 style="margin: 0in 0in 10pt; text-align: justify;">
<u><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; font-size: small;">Elements of CDN </span></u></h1>
<ul style="text-align: left;">
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l3 level1 lfo3; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"><b style="mso-bidi-font-weight: normal;">Request: </b>A request for a specific content (for e.g. a webpage) is made from the End user, which is redirected to the nearest image server. This is done by the use of a protocol known as Web Cache Communication Protocol (WCCP).</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l3 level1 lfo3; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"> </span></span><span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"><b style="mso-bidi-font-weight: normal;">Distribution: </b>Once the request is received, a distribution element in the CDN forwards the request based on the point of origin, content availability, location and servers' global load.</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l3 level1 lfo3; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c; font-family: Arial;"> </span><span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"><b style="mso-bidi-font-weight: normal;">Delivery: </b>Delivery of the requested content is made by this element by using routing and switching protocols.</span></span></div>
</li>
</ul>
<div class="MsoNormal" style="margin: 0in 0in 10pt; text-align: justify;">
<u><span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"> <b>Algorithms/Protocols used in Request Routing</b></span></span></u></div>
<ul style="text-align: left;">
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">A variety of algorithms are used for this purpose. These include <b style="mso-bidi-font-weight: normal;">Global Server Load Balancing, DNS-based request routing, Dynamic metafile generation </b>etc.</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;">Global Server Load Balancing</i></b> (GLSB) enables the content to be obtained from a server pool in a sequential manner using round-robin method and redirect the request in case of inactive server sessions.</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;">DNS-based request routing</i></b>: Here when a request is made (URL), the local DNS server provides the IP address of the nearest matching CDN node. If the Local DNS is not able to resolve the URL, it forwards the request to the Root DNS server, which then provides the nearest possible CDN server IP. </span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"><strong>D</strong><i style="mso-bidi-font-style: normal;"><strong>ynamic metafile generation</strong></i> includes creation of a metafile, which has an ordered hierarchy of CDN domains connected to a Main server and helps in the load balancing on each of CDN nodes connected to it. </span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"><strong>I</strong><strong>CAP (Internet Content Adaptation Protocol), OPES (Open Pluggable Edge Services) and ESI</strong> <b style="mso-bidi-font-weight: normal;">(Edge Side Includes)</b> are the protocols used for accessing data through a request in CDNs.</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;">ICAP</i></b> is a high level protocol that helps in generating http requests and delivers contents from the CDN servers.</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;">OPES</i></b> uses a Processor in order to share contents to the end users. This processor duplicates the content at each CDN node and traces the route followed by each request made by the user and notifies the user once the content is found. </span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;"><b style="mso-bidi-font-weight: normal;"><i style="mso-bidi-font-style: normal;">ESI</i></b> avoids back end processing delays hence providing dynamic contents with ease. It breaks web content into fragments and delivers dynamic contents to end users.</span></span></div>
</li>
</ul>
<h2 style="margin: 0in 0in 10pt;">
<u><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif; font-size: small;">Benefits of CDNs</span></u></h2>
<ul style="text-align: left;">
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">Accelerates web-based applications</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">Low connectivity latency</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">Optimization of capacity per user</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c;"><span style="font-family: Arial, Helvetica, sans-serif;">Faster and reliable access to contents</span></span></div>
</li>
<li><div class="ListParagraph" style="margin: 0in 0in 10pt 0.5in; mso-list: l7 level1 lfo5; text-align: justify; text-indent: -0.25in;">
<span style="color: #134f5c; font-family: Arial;"> L</span><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">ow network loads</span></div>
</li>
</ul>
<a href="http://www.codeproject.com/script/Articles/BlogArticleList.aspx?amid=5645925" rel="tag" style="display:none" >CodeProject</a></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-8485915646383933212?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-46396603394259210722011-05-14T04:28:00.000-07:002011-05-14T04:29:44.382-07:002011-05-14T04:29:44.382-07:00Improving application start up time having signed assemblies<div dir="ltr" style="text-align: left;" trbidi="on"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;">I guess all are aware that signed assemblies need verification from CA. This verification can create panic, when certification authority is not present on the same machine. In that case, assemblies require internet access. Situation can be more problematic, if there is no internet or network access on that machine. In absence of network access .Net thread might timeout waiting to connect. This issue can be avoided by adding following setting in machine.config:</span><br />
<span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; border-collapse: separate; color: #333333; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span class="Apple-style-span" style="line-height: 18px;"><span style="color: #134f5c; font-family: Arial, Helvetica, sans-serif;"><configuration><br />
<runtime><br />
<<b>generatePublisherEvidence enabled="false"</b>/><br />
</runtime><br />
</configuration></span></span></span></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-4639660339425921072?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-71847279996731012812011-04-19T06:37:00.000-07:002011-04-19T06:38:06.460-07:002011-04-19T06:38:06.460-07:00Security concerns with serialization<div dir="ltr" style="text-align: left;" trbidi="on"><span style="color: #134f5c;">Serialization can allow other code to see or modify object instance data that would otherwise be inaccessible. Therefore, code performing serialization requires the <strong><em>SecurityPermission</em></strong> attribute from System.Security.Permissions namespace with the <em><strong>SerializationFormatter</strong></em> flag specified. The <strong><em>GetDataObject</em></strong> method should be explicitly protected to help protect your data.</span></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-7184727999673101281?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-85204025345001759842011-04-17T07:24:00.000-07:002011-04-17T07:24:28.930-07:002011-04-17T07:24:28.930-07:00Inner workings of Deserialization<div dir="ltr" style="text-align: left;" trbidi="on"><span style="color: #134f5c;">Within the runtime, deserialization can be a complex process. The runtime proceeds through the deserialization process sequentially, starting at the beginning and working its wasy through to the end. The process gets complicated if an object in the serialized stream refers to another object.</span><br />
<br />
<span style="color: #134f5c;">If an object references another object, the <strong><em>Formatter</em></strong> queries the <strong><em>ObjectManager</em></strong> to determine whether the referenced object has already been deserialized (a backward reference), or whether it has not yet been deserialized ( a forward reference). If it is a forward reference, the <strong><em>Formatter</em></strong> registers a <strong><em>fixup</em></strong> with the <strong><em>ObjectManager</em></strong> . A <strong><em>fixup</em></strong> is the process of finalizing an object reference after the referenced object has been deserialized. Once the referenced object is deserialized, <strong><em>ObjectManager</em></strong> completes the reference. </span></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-8520402534500175984?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-6449791320240144132011-04-17T06:50:00.000-07:002011-04-17T06:50:47.631-07:002011-04-17T06:50:47.631-07:00Limiting Threads in a ThreadPool<div dir="ltr" style="text-align: left;" trbidi="on"><span style="color: #134f5c;">The ThreadPool class supports methods for setting the number of minimum and maximum thread in the thread pool. In most circumstances, yhe number of threads is the pool is set at optimum numbers. If you find that your application is being constrained by the threads in th thread pool, you can set the limits yourself. </span><br />
<span style="color: #134f5c;">There are two types of situations where you will want to change the thread pool thread limits: thread starvation and startup thread speed.</span><br />
<br />
<span style="color: #134f5c;">In thread-starvation scenario, your application is using the thread pool but is being hampared because you have two many work items and you are reaching the maximum number of threads in the pool. To set the high watermark of threads for your application, you can simply use ThreadPool.SetMaxThreads.</span><br />
<br />
<span style="color: #134f5c;">In cases where the startup costs of using the thread pool are expensive, increasing the minimum number of threads can improve performance. The minimum number of threads dictates how many threads are created immediately and set to wait for new work to do. Typically, the ThreadPool limits the number of new threads to be created during the running of a process to two per second. If your application need more threads created faster, you can increase this size. Setting minimum numbers of threads can be done by using ThreadPool.SetMinThreads</span></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-644979132024014413?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-35804248369453945422011-04-17T06:21:00.000-07:002011-04-17T06:21:07.386-07:002011-04-17T06:21:07.386-07:00Deploying COM-Enabled Assemblies<div dir="ltr" style="text-align: left;" trbidi="on"><span style="color: #134f5c;"> </span><span style="color: #134f5c;">Although an assembly can be created visible to COM, one should follow below guidelines to ensure that things work as planned:</span><br />
<ul><li><span style="color: #134f5c;">All classes must use a default constructor with no parameters.</span></li>
<li><span style="color: #134f5c;">Any type that is to be exposed must be public.</span></li>
<li><span style="color: #134f5c;">Any member that is to be exposed should be public.</span></li>
<li><span style="color: #134f5c;">Abstract classes will not be able to be consumed.</span></li>
</ul><span style="color: #134f5c;">After these criteria are met, the assembly is essentially ready to be exported. There are two mechnisms to do so. One can use VS or a command line utility(TlbExp.exe). First you need to compile the type through Visual Studio's build mechanism or through command line compiler as</span><br />
<span style="color: #134f5c;"> <strong>csc /t:library ComVisiblePerson.cs</strong></span><br />
<span style="color: #134f5c;">Next you need to use Type Library Exporter Utility. This should be done from VS command prompt:</span><br />
<span style="color: #134f5c;"> <strong>tlbexp ComVisiblePerson.dll /out:ComVisiblePersonlib.tlb</strong></span><br />
<span style="color: #134f5c;">Next oyu need to create resource script (ComVisiblePerson.res) with the following Interface Definition Language (IDL) definition:</span><br />
<span style="color: #134f5c;"> <strong>IDR_TYPELIB1 typelib "ComVisiblePersonlib.tlb"</strong></span><br />
<span style="color: #134f5c;">then you recompile the application with the new resource file added as:</span><br />
<span style="color: #134f5c;"> <strong>csc /t:library ComVisiblePerson.cs /win32res:ComVisiblePerson.res</strong></span><br />
<br />
<br />
</div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-3580424836945394542?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0tag:blogger.com,1999:blog-2254111756987838850.post-40189604073332712022011-01-18T07:48:00.001-08:002011-01-18T07:48:59.393-08:002011-01-18T07:48:59.393-08:00Moving a type (i.e. class) to another assembly<div style="font-size: 13px; line-height: 18px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="color: #134f5c; font-family: Verdana, sans-serif;">In .NET, one often refers to other assemblies that contain specific modules that you can use in your application. Say, you reference a DLL that contains some classes that you will use in your application. Suppose the application is deployed. Now, suppose you want to move one class of the DLL to another assembly. What can you do in this situation with old coding methodoligies? The old methodologies say,</span></div><ul style="font-size: 13px; line-height: 18px; margin-bottom: 1em; margin-left: 2em; margin-right: 1em; margin-top: 1em; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><li style="list-style-image: initial; list-style-position: outside; list-style-type: disc; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="color: #134f5c; font-family: Verdana, sans-serif;">Remove the class from the existing DLL.</span></li>
<li style="list-style-image: initial; list-style-position: outside; list-style-type: disc; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="color: #134f5c; font-family: Verdana, sans-serif;">Create another DLL (assembly) using that class.</span></li>
<li style="list-style-image: initial; list-style-position: outside; list-style-type: disc; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="color: #134f5c; font-family: Verdana, sans-serif;">Recompile both the DLLs.</span></li>
<li style="list-style-image: initial; list-style-position: outside; list-style-type: disc; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="color: #134f5c; font-family: Verdana, sans-serif;">From your application, add a reference to the new DLL.</span></li>
<li style="list-style-image: initial; list-style-position: outside; list-style-type: disc; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="color: #134f5c; font-family: Verdana, sans-serif;">Recompile the application.</span></li>
<li style="list-style-image: initial; list-style-position: outside; list-style-type: disc; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="color: #134f5c; font-family: Verdana, sans-serif;">Re-deploy the whole thing.</span></li>
</ul><div style="font-size: 13px; line-height: 18px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="color: #134f5c; font-family: Verdana, sans-serif;">Wouldn't it be nice to leave the deployed application untouched, and make whatever changes are needed in the DLLs? Obviously, that would be nicer. That's where the<i>TypeForwardedTo</i> attribute comes into the scene. By using this, you can move your necessary classes out to a new assembly. Now, when your application looks for the class in the old DLL, the old DLL tells your application (the JIT compiler—to be precise), "Well, the person (class) who lived here has moved to another location; here is the address." It gives in the address, your application follows the address, there it finds the class, and things go on as is.</span></div><div style="font-size: 13px; line-height: 18px; margin-bottom: 1.5em; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><span class="Apple-style-span" style="color: #134f5c; font-family: Verdana, sans-serif;">So, simply you will create another assembly (DLL) and move the class to the new assembly. Then, you have to compile the new DLL and add a reference to it from the previous DLL. Then, you will add a TypeForwardedTo attribute in the previous DLL to mean <i>a specified type is forwarded to some other assembly</i>. Then, you have to recompile the old DLL and, as a result, you will have two DLLs in the release folder of the previous DLL. Now, you just have to place both the DLLs in the root of the deployed application (or wherever the old DLL is).</span></div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2254111756987838850-4018960407333271202?l=shwetamannjain.blogspot.com' alt='' /></div>Shweta Jainhttp://www.blogger.com/profile/00600588932289815127noreply@blogger.com0