Welcome to MSDN Blogs Sign in | Join | Help

Browse by Tags

All Tags » C# / .NET / Coding   (RSS)

Is interlocked increment followed by comparison thread safe?

Sorry about the blog title, my imagination failed me :(. In our internal alias someone asked the question "Is the following thread safe" if(Interlocked.Increment(ref someInt) == CONSTANT_VAL) { doSomeStuff(); } My instant reaction was no because

C/C++ Compile Time Asserts

The Problem Run time asserts are fairly commonly used in C++. As the MSDN documentation for assert states " (assert) Evaluates an expression and, when the result is false, prints a diagnostic message and aborts the program. " There is another

Silverlight on Nokia S60 devices

In many of my blog posts (e.g. here and here ) I refer to .NET Compact Framework and Symbian OS (S60) and obviously folks keep asking me via comments (or assume) that we are porting .NETCF on S60 devices. So I thought it's time to clarify :) The short

Who halted the code

Today a bed time story involving un-initialized variable access and a weird coincidence. Couple of weeks back I was kind of baffled with a weird issue I was facing with the .NET Compact Framework Jitter. We were making the Jitter work for Symbian OS (S60)

Hex signatures

Frequently in code we need to add bit patterns or magic numbers. Since hex numbers have the alphabets A-F folks become creative and create all kinds of interesting words. Typical being 0xDEAD, 0xBEEF, 0xFEED or various combination of these like 0xFEEDBEEF.
Posted by abhinaba | 0 Comments

Back To Basics: Finding your stack usage

Handling stack overflow is a critical requirement for most Virtual Machines. For .NET Compact framework (NETCF) it is more important because it runs on embedded devices with very little memory and hence little stack space. The .NETCF Execution Engine

A* Pathfinding algorithm animation screen saver

I'm trying to learn WPF and IMO it is not a simple task. Previously whenever I upgraded my UI technology knowledge it had been easy as it build on a lot of pre-existing concepts. However, WPF is more of a disruptive change. I decided to write some simple

How Many Types are loaded for Hello World

<Updated> Consider the following super simple C# code namespace SmartDeviceProject1 { class Program { static void Main(string[] args) { System.Console.WriteLine("Hello"); } } } Can you guess how many managed Type gets loaded to run this? I was doing

Designer for my path finding boards

I'm writing a small application (or rather a screen saver) that animates and demonstrates A* search algorithm . The idea is simple. On screen you see a start and end point and some random obstacles in between them. Then you see animation on how A* algorithm

Back to Basic: Using a System.Threading.Interlocked is a great idea

I just saw some code which actually takes a lock to do a simple set operation. This is bad because taking locks are expensive and there is an easy alternative. The System.Threading.Interlocked class and its members can get the same job done and much faster.

String equality

akutz has one of the most detailed post on string interning and equality comparison performance metrics I have ever seen. Head over to the post here I loved his conclusion which is the crux of the whole story. " In conclusion, the String class’s
Posted by abhinaba | 1 Comments

Writing exception handlers as separate methods may prove to be a good idea

Let us consider a scenario where you catch some exception and in the exception handler do some costly operation. You can write that code in either of the following ways Method-1 : Separate method call public class Program { public static void Main(string[]

Do namespace using directives affect Assembly Loading?

The simple answer is no, the inquisitive reader can read on :) Close to 2 year back I had posted about the two styles of coding using directives as follows Style 1 namespace MyNameSpace { using System; using System.Collections.Generic; using System.Text;

Auto generating Code Review Email for TFS

We use a small command line tool called crmail to auto-generate code review email from shelveset. I find the whole process very helpful and thought I'd share the process and the tool (which has some really cool features). Features Automatic generation

C# generates virtual calls to non-virtual methods as well

Sometime back I had posted about a case where non-virtual calls are used for virtual methods and promised posting about the reverse scenario. This issue of C# generating callvirt IL instruction even for non-virtual method calls keeps coming back on C#
Posted by abhinaba | 2 Comments
More Posts Next page »
 
Page view tracker