Following up on the previous post we are now going to modify the LocklessQueue<T> to allocate a class for an array of items rather than just a single item. Most of this work will be in the Item class itself with a few changes to the Enqueue method. Again we have to ensure that both [...]

 

From time to time I see posts about removing the use of lock() from producer/consumer queues where the number of threads operating are limited. This is an exploration into writing such a queue, the techniques used, and how to create the thread interactions without the use of locks. Step 1 – Building the first thing [...]

 

So first off this is not new, it’s been around for a long, long while. One issue I have with IDisposable is that for whatever reason .Net did not include a base class for handling the details… I admit you may not always be able to leverage it since you may have a base class, [...]

 

This one is actually something of a triviality, yet it can be very useful at times. Now a word of caution is due here, this object is built on System.Threading.Timer and should not be used to enqueue 12 million work items. Yet if you need to perform a simple task at some time in the [...]

 

Most people I’ve seen online compute a simple hash of password + salt for persistence and authentication. This is the accepted standard in a straight-forward solution: byte[] Hash(string password) { byte[] pass = System.Text.Encoding.UTF8.GetBytes(password); //Create the salt to use byte[] salt = new byte[32]; new RNGCryptoServiceProvider().GetBytes(salt); //Create the hash of password and salt HashAlgorithm hashAlgo [...]

 

So recently I’ve been working heavily with some of the cryptography stuff in .Net and adding a large amount of it to my open source library. One of the many things I needed to perform was simply encrypting and decrypting a piece of data with a password. It seems everyone out there is using Rfc2898DeriveBytes [...]

May 102010
 

Recently I was killing time on stackoverflow and found this question: What is the best comment in source code you have ever encountered? There are a lot of great quotes in there. If you haven’t seen it already it worth a read when you want to kill some time. I’d also add my own to [...]

 

As promised in the previous post “How to implement a generic Shallow-Clone for an object in C#” this will demonstrate deep-cloning objects that don’t explicitly support the behavior. Before I continue I will again state that I don’t recommend this approach. It will be many times slower than a properly implemented Clone() and can cause [...]

 

This implementation makes heavy use of the FormatterServices object used by serialization: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatterservices_members.aspx It provides several helpful methods in this case that are aware of custom serialization options like [NonSerialized]. In the case of an object not being marked [Serializable] you have to create field list manually. Here is an example shallow object clone: using [...]

 

How to throw the InnerException of a TargetInvocationException without loosing stack details? I’ve been plagued by this problem for some time. There are a few common solutions to this: Option #1 – just leave it alone. The downfall here is that specific types of exceptions cannot be caught easily in calling code. In some instances [...]