Blog Stats
  • Posts - 94
  • Articles - 0
  • Comments - 10
  • Trackbacks - 0

 

November 2007 Entries

Create a Singleton in C#

Sometimes you need an object instance rather than a static class but you really want that object instance to be globally unique to your application, e.g. there can be only one.  Enter the singleton pattern: public class MySingleton {     private static volatile MySingleton _instance;     private static object _sync = new object();     public static MySingleton Instance     {         get         {             if (_instance == null)             {                 lock (_sync)                 {                     if (_instance == null)                     {                         _instance =...

Determine Approximate Memory Used by an Object

Curious as to how much memory your object or list of objects is taking up?  Here's a quick way to get an approximation: long startMem = GC.GetTotalMemory(true); SortedDictionary<string, MyClass> myDictionary = GenerateDictionary(); long endMem = GC.GetTotalMemory(true); long byteSize = endMem - startMem; long bytesPerItem = byteSize / myDictionary.Count; Console.WriteLine("Starting memory: {0} bytes", startMem); Console.WriteLine("Ending memory: {0} bytes", endMem); Console.WriteLine("Approx dictionary size: {0} bytes", byteSize); Console.WriteLine("Bytes per item: {0} bytes", bytesPerItem); And off you go!

Embed Resources into your .Net Projects

Worrying about file paths, locations, availability, and security of your project's resource can be a real pain.  Fortunately, you can easily embed resources into your project's DLL and reference them with ease from your code.  Here's an example of how to reference an embedded XSD: First, to embed the resource, right click on the file and choose Properties.  Next, switch the Build Action on the file to Embedded Resource. Now, when you compile your project, your resource will be compiled into the DLL with the default namespace of the project/folder location of the file within your project, e.g. if your default...

November 2007 Issue of TechNet Magazine: IT Toolbox

The November 2007 issue of TechNet Magazine is out on the website. Check out my IT Toolbox column here: http://technet.microsoft.com/magazine/bbf6a03e-f62d-4ff6-8c81-da5fc80cb402 In this issue I covered: My Screen Recorder Pro Video Screen Capture PerfectDisk 8 Disk Defrag Network Warrior (Book Review) WhoLockMe Manage File Locks DNSStuff.com DNS Tools

 

 

Copyright © Greg Steen