Archive

Archive for March, 2009

General form of C# Object Initializers

March 29, 2009 3 comments

C# has a language feature that allows several properties of an object to be assigned to as a suffix to a new expression, namely the object initializer:
Read more…

Categories: syntax, wish Tags: ,

Readonly Fields and Thread Safety

March 6, 2009 1 comment

In C# you can mark the fields of a type as readonly (indeed you generally should if it’s a struct). By doing so, you make it illegal to change the fields except in a constructor of the type.

The advantage of this is that readonly data can be shared freely between threads without any thread causing updates that may be seen "in progress" by other threads, simply because there never will be any updates.

But is this strictly speaking true? Nope.

Read more…

Categories: immutable, threads Tags: ,

The Amazing Speed of the .NET Garbage Collector

March 1, 2009 1 comment

Coming from a C++ background, I always balk at designs that involve lots of small heap allocations. It’s something I’m gradually training myself to stop doing, because in managed code, it’s a completely irrational concern.

Given the constant usefulness of lambdas for things like this, it is worth reassuring myself (and others) that the overhead of such techniques is negligible. I already knew it probably was, but I had no idea just how negligible. It really is ridiculously unimportant.

Read more…

Categories: GC Tags: ,