Wednesday, December 30, 2015

Upgrading the Computer


This is going to be a hardware blog post with some technology then and now mixed in.

The New Machine

I recently upgraded my computer.  It's been over six years since I assembled my last PC, so it was time.  One of the advantages of waiting so long is that I can spend less money and still get a significant increase in computing power vs. the older machine.  My real reason for waiting so long is that I've done this task dozens of times since the early 80's when I purchased my first machine (which as a Macintosh, when it was called the Macintosh computer).  So I have many painful memories of upgrading hardware, looking for the correct drivers and attempting to figure out how to configure and make things work.

I did some research on-line.  My first priority was hard drive speed.  I was one of the early adopters of the SSD.  To put it into perspective, I paid $700 for a 256 Gig SSD hard drive with a SATA interface.  That's SATA as in, before SATA 2.  I purchased Windows 7 at the same time because Windows 7 just came out (just to give an idea of how long ago that was).  I wanted to see what was available and I was very happy to discover that they are finally abandoning the hard drive interface.  Let's face it, an SSD is not a hard drive but a memory stick.  The new SSDs have an interface called the M.2 which mounts right on the motherboard.  The M.2 connector uses the PCI-Express 3 bus.  No wires!  Yay!  I chose the new Samsung 950 Pro, which comes in two sizes: 256 Gig and 512 Gig.  I ended up buying the 512Gig drive.  

My old SSD runs at 250Mb/s, the new drive runs at 2500Mb/s.  Yeah, it's 10 times faster.

So I started with the hard drive this time and built my computer around that component.  Usually, I start with the CPU.  My next task was to pick out a CPU and that was rough.  I've been out of the hardware business for too long and I had to compare speed stats with my existing PC to get a comparison.  I settled on the Intel Core i7-4790K, which is a 4Ghz quad core.  It's not cutting edge, but it's over 5 times faster than my previous Core-2 Duo that was using.  

Next up was the motherboard, obviously.  Let's face it, once you pick out a CPU, you need to research a motherboard to match.  ASRock seems to be the common brand these days.  ASUS is still big and I've purchased a couple of their boards in the past.  They go way back.  I stumbled onto ASRock because it was the first motherboard on NewEgg's website in the list of Intel motherboards that fit the socket of CPU I was looking for.  Oh, and it had an M.2 socket (I'm betting they all do by now, and some have two slots).  My choice was the Fatal1ty Z97 Killer.

Next was memory.  Oh, there are so many choices.  I've bought a lot of G.Skill memory sticks in my lifetime.  I settled for some DDR3 2400 16Gb sticks (actually 2x8Gig).  I bought 2 packs so I have 32Gig total memory, but they were only $75 a pack.  Which is cheap.  I use a lot of memory because I do development work and I run multiple instances of SQL server on my PC for development purposes.  I'm also researching virtual machine stuff like Docker.  So it'll be nice to have oodles of memory.

Now for the power supply.  One thing I learned a long time ago, was not to skimp on the size of the power supply.  Overkill is good.  So I started looking on NewEgg for a power supply and I stumbled onto the new Corsair power supplies and discovered just how sweet that technology has come.  The RMx series has coords that have plugs on both sides, so you don't have to install a metal box with a billion wires hanging out inside your computer.  Not to mention that most of those wires are never used.  I bought the 850 Watt model.  

Nearing the finish line.  The video card.  Sigh, I've been out of it for so long, I'm not sure what is hot and what is not.  I can tell by the prices, but I've already sunk some cash in the above hardware and I was trying not to make this into a $3,000 purchase, so I settled on the EVGA GeForce GTX 960.  It was selling for about $200.  Which is really a cheap price for a graphics card.  It takes up 2 slot positions, which is pretty normal these days and it came with 2GB of memory (they make a 4GB version as well).  My primary concern with a video card is to handle my 30" monitor, which requires a dual-link DVI connection (or I could adapt to HDMI).  The resolution of this monitor is 2560 x 1600, so it won't work with a cheap card.  If you're planning to build a gaming system, I would advise you research the video card first, then build your system around that.

The next component I bought is optional, but I have experience with CPUs and loud fans.  In fact, I assembled a Pentium 4 machine with a tiny jet engine attached to it (it was the Intel fan).  That prompted me to buy my first large and quiet copper fan.  So I also bought the Deepcool Gammaxx CPU cooler.  It is quiet!  

Oh and the blue lights are cool too!

The final piece was the case and I ended up going generic.  I spent too much time trying to pick out a case and I ended up choosing the Cooler Master HAF 912.  Which turned out to be a really nice case.


The case arrived first so I had a box sitting around my computer room for a while.  Then the parts arrived, but UPS needed a signature so I had them hold at the distribution center.  I was happy to see that all the parts came in one large box.  Nothing worse than receiving all the parts, except the CPU (or some other critical part).  

The first thing to do is unpack the motherboard and get the case laid out.  I have done this so many times, I don't have to even think about how to assemble a computer any more.  So I positioned the motherboard and identified which holes in the case will need posts and installed the extra posts.  It's important to put in all the posts because that makes gives the motherboard a very solid foundation so it doesn't bend when you insert a card or plug in a power connector.  Then I attached the motherboard.

There is one step I always forget and curse myself every time I do it.  This time was no different.  I always forget to put the shield on the back of the case before installing the motherboard.  Some of my older PC's didn't have that shield because I didn't want to reassemble the machine.  This time I took the motherboard back out and put the shield in.  Then re-attached the motherboard.

The next component I installed was the hard drive.  There is a flush mount socket between the edge card connectors.  The socket area also has some screw holes and a screw that holds the board to the motherboard.  That's pretty nice, since it doesn't rely on the tightness of the socket to hold it in.  Here's what it looks like when it's mounted on a motherboard:

Next, I mounted the CPU.  This is a painful process.  I am not a fan of the LGA 1150 fan configuration.  The plastic posts that screw into the motherboard are difficult to mount tight.  The Deepcool CPU cooler has several brackets to mount the fan to many types of CPUs and after looking at the other options, the LGA 1150 is the most annoying.  I do like the fact that processor companies have done away with the pins.  No chance of breaking any, not to mention the fact that they have become so small that you can't see them without a magnifying glass (or maybe my eyes are just getting bad... Nahh).

At this point, I would recommend connecting all the connections from the front panel.  These include stuff like the on/off button, USB connectors, the HDD light and maybe the earphone jack and microphone jack (or any other connections that are on the front panel of your case).  Don't do what I usually do.  I mound the video card and power supply first, then I try to squeeze my hands between the two to try and plug in tiny connectors in a slot the width of a finger.

Once the front panel connections are completed, mount the memory, the video card and finally the power supply.  The power supply is usually last because once the wires are connected, it gets tight inside the case and you need to move wires around to get cards into their slots.

When the machine is powered up, you can connect a network cord and run the BIOS update.  This is sweet.  In the "good ole' days" we had to download the BIOS update software to another computer, put it on a bootable device (like a CD rom or floppy), then flash the BIOS.   

Installing Windows

For now, I'm re-installing my Windows 7 Ultimate edition on this PC.  I'll perform the Windows 10 upgrade later.  In the bios, the new SSD was recognized right away but Windows 7 needs a driver.  This driver can be installed on a USB stick which beats the old method of using a floppy drive (ouch, I just revealed how "old" I am).  It took some effort to find the right drivers, but these worked:

Samsung windows 7 driver
Then the windows install took another 5 minutes or so.

One of the problems with being the first person on the block to buy Windows on a disc is that it has no patches installed.  So the patch process took a couple of days and about 200 or so reboots (only exaggerating a little).  In the middle was an IE upgrade and after I installed Visual Studio 2015 Community edition and MS SQL Server 2014, there were more updates.  

I intended to just move my old 2TB hard drive from the old machine for now.  It has photos and other bulk storage.  It didn't work with the new motherboard.  Not sure what the issue was, but I ended up purchasing a 4TB SATA-3 hard drive and installing it clean.  That worked right out of the box.  Copying from the old drive required me to share the drive (with permissions), and doing a bulk copy and paste, and leaving that go for a few hours.

The new machine doesn't have the quick-boot option because it's not supported under Windows 7.  However, it still boots in about 2 to 3 seconds.  Very nice.  I also run CrashPlan, which I use for backup to cloud storage.  This is my "just in case the house burns down" backup system.  Like any backup software, that software can kill the speed of a computer in no time.  On this machine, I can't tell if its running or not.  That is due to two factors: Super fast hard drives and lots of memory.

Performance Tests

Passmark makes a performance test that I've used on many machines.  This machine benchmarked at a total of 5426.  The CPU benchmarked a little slower than the Intel i7-4790K @ 3.3 Ghz.  The 2D benchmarks are better than most of the graphics cards it compares with (there are a lot of tests).  The 3D tests came in about about half the speed of the GeForce GTX 960.  Which I expected because it cost about half as much for this card.  The memory performance was better than all other memory systems compared, except the DDR4 SDRAM PC4-17000 Crucial for the threaded tests.  Not sure if that's going to matter much.  The hard disk test was as expected.  The MBytes transferred per second test blows away any other disk.  It rated at 821 and the next fasted SSD was the Kingston SH100S3120G which clocked at 262.7.

My own real-world tests included the use of SQL Server, which is blazing fast to query data.  Photoshop pops up like it's a small utility program.  I opened 87 photos from a directory containing raw jpg files from my camera that range from 5Mb to 8Mb in size.  Photoshop opened these photos without choking and they opened within 30 seconds or so.  My old PC would have died after about 20 photos.  Visual Studio will compile and run a program so fast that I can't tell if it did anything.  So I put a break-point in the code and it just appeared at the break-point right as I hit the F-5 key. 


My first PC was a 386SX running at running at 16Mhz.  I don't remember how much memory the machine had in it but I do remember the hard drive was somewhere in the neighborhood of 160 Megabytes.  It was barely able to play Doom, not possible to play Descent.  

I skipped over the 386 and went right into the 486DX2 running at 66Mhz.  That machine was fast!  That was the first machine I installed Windows 95.  There were several hard drive, memory and video card upgrades during this time.  I remember upgrading the sound card to the Sound Blaster AWE32.  Now I just use on-board surround sound.

My next motherboard was the 90Mhz Pentium.  I remember the 1.9 Gigabyte hard drive coming out about then.  I had to partition that thing into 4 drives because DOS couldn't support such a large hard drive when they were first introduced.

Next came the 200Mhz Pentium Pro.  That had a really cool giant chip.  The motherboard for that machine had a new 6-pin power connector on it and I was unable to use my existing power supply.

After that came a Pentium II (I think it was a 400Mhz version).  This was the new socket that had an integrated heat sink and fan.  I was never much of a fan of that configuration.  I ended up waiting out past the Pentium III.  I upgraded to Windows XP on this machine.  40 Gigabyte hard drives came out around this time.  I remember thinking that my first hard drive was 40 Megabytes that I purchased for $900 in 1986 for my Macintosh.  I don't think I paid much more than $100 for the 40 Gig drive at the time.

The Pentium 4 arrived and I jumped on that CPU.  Mine ran at 1Ghz.  I used this machine for a long time.

My last machine was a Dell Precision workstation.  This was configured with a Core-2 Duo and came with 2Gb of memory and as mentioned earlier I added a 256Gb SSD.  I also had to buy a video card to support the new monitor.  I finally ditched my old 22" video tube for a flat screen and I forked over the $1100 for the 30" dell 3007WFPHC monitor.

What comes next?  Something bigger, better and faster!

Monday, December 7, 2015

Side by Side Error


In this blog post I'm going to demonstrate how to generate an error that is difficult to find.

The Error

The error message that I'm going to show can be caused by a lot of different things.  The cause of this error will be the use of an "&" symbol inside the app.config file.  The error message you get will be:

The application has failed to start because its side-by-side configuration is incorrect.  Please see the application event log or use the command-line sxstrace.exe tool for more detail.

If you get this error, you'll need to go to the control panel and open up the event viewer.  Then look under the applications section and look for a side-by-side error message.  This message will probably point you in the right direction.  Now I'm going to show how to generate this error with a few lines of code.  First, I'm going to create a console program in C# with Visual Studio 2015:

using System;
using System.Configuration;

namespace SideBySideBlogPost
    class Program
        static void Main(string[] args)
            string temp = ConfigurationManager.AppSettings["test"];

            Console.WriteLine("test output");

Then I'm going to create an app.config file and add the following inside the <configuration> section:

    <add key="test" value="test output & more testing"/>

If you are using Visual Studio 2015, you'll notice that you can't compile the program because the "&" symbol is not allowed.  So I removed the symbol, compiled the program and edited it in the resulting app.config file in the bin/debug directory.  Then ran the program.  Here's what the event viewer looks like:


Saturday, December 5, 2015

Serializing Data


In this blog post I'm going to talk about some tricky problems with serializing and deserializing data.  In particular, I'm going to demonstrate a problem with the BinaryFormatter used in C# to turn an object into a byte array of data.

Using the BinaryFormatter Serializer

If you are serializing an object inside your project and storing the data someplace, then deserializing the same object in your project, things will work as expected.  I'll show an example.  First, I'll define a generic object called AddressClass.  Which stores address information:

public class AddressClass
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }

The first thing you'll notice is that there is a [Serializable] attribute.  This is needed in order for BinaryFormatter to serialize the object.  Next, I'll create an instance of this object in my console application and populate with some dummy data:

// create an instance and put some dummy data into it.
var addressClass = new AddressClass
    Address1 = "123 Main st",
    City = "New York",
    State = "New York",
    Zip = "12345"

Now we're ready to serialize the data.  In this example, I'll just serialize this object into a byte array:

// serialize the object
using (var memoryStream = new MemoryStream())
    var binaryFormatter = new BinaryFormatter();
    binaryFormatter.Serialize(memoryStream, addressClass);

    storedData = memoryStream.ToArray();

There's nothing fancy going on here.  You can even use a compressor inside the code above to compress the data before saving it someplace (like SQL or Redis or transmitting over the wire).  Now, I'm going to just deserialize the data into a new object instance:

//deserialize the object
AddressClass newObject;
using (var memoryStream = new MemoryStream())
    var binaryFormatter = new BinaryFormatter();

    memoryStream.Write(storedData, 0, storedData.Length);
    memoryStream.Seek(0, SeekOrigin.Begin);

    newObject = (AddressClass)binaryFormatter.Deserialize(memoryStream);

If you put a break-point at the end of this code as it is, you can see the newObject contains the exact same data that the addressClass instance contained.  In order to make all the code above work in one program you'll have to include the following usings at the top:

using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

Deserializing in a Different Program

Here's where the trouble starts.  Let's say that you have two different programs.  One program serializes the data and stores it someplace (or transmits it).  Then another program will read that data and deserialize it for its own use.  To simulate this, and avoid writing a bunch of code that will distract from this blog post, I'm going to dump the serialized data as an array of integers in a text file.  Then I'm going to copy that raw text data and then use it in my second program as preset data of a byte array.  Then I'm going to copy the AddressClass code above and the deserialize code above and put it in another program.  This should deserialize the data and put it into the new object as above.  But that doesn't happen.  Here's the error that will occur:

Unable to find assembly 'SerializatingDataBlogPost, Version=, Culture=neutral, PublicKeyToken=null'.

This error occurs on this line:

newObject = (AddressClass)binaryFormatter.Deserialize(memoryStream);

Inside the serialized data is a reference to the dll that was used to serialize the information.  If it doesn't match, then the assumption is that BinaryFormatter will not be able to convert the serialized data back into the object defined.

If you dig around, you'll find numerous articles on how to get around this problem.  Using a BindToType object is one method as shown here:

Unable to find assembly with BinaryFormatter.Deserialize

And it goes down a rabbit hole from there.  

Another Solution

Another solution is to serialize the data into JSON format.  The Newtonsoft serializer is very good at serializing objects into JSON.  After that, the deserialized data can be cast back into the same object inside another dll.  Use the NuGet manager to add Newtonsoft to your project.  Then use the following code to serialize your addressClass object:

// serialize the object
var serializer = new JsonSerializer();
string resultSet = JsonConvert.SerializeObject(addressClass);

This will convert your object into the following string:

{"Address1":"123 Main st","Address2":null,"City":"New York","State":"New York","Zip":"12345"}

Inside another project, you can deserialize the string above using this:

// deserialize object
AddressClass newObject;
newObject = JsonConvert.DeserializeObject<AddressClass>(resultSet);

Compressing the Data

JSON is a text format and it can take up a lot of space, so you can add a compressor to your code to reduce the amount of space that your serialized data takes up.  You can use the following methods to compress and decompress string data into byte array data:

private static byte[] Compress(string input)
    byte[] inputData = Encoding.ASCII.GetBytes(input);
    byte[] result;

    using (var memoryStream = new MemoryStream())
        using (var zip = new GZipStream(memoryStream, CompressionMode.Compress))
            zip.Write(inputData, 0, inputData.Length);

        result = memoryStream.ToArray();

    return result;

private static string Decompress(byte[] input)
    byte[] result;

    using (var outputMemoryStream = new MemoryStream())
        using (var inputMemoryStream = new MemoryStream(input))
            using (var zip = new GZipStream(inputMemoryStream, CompressionMode.Decompress))

        result = outputMemoryStream.ToArray();

    return Encoding.Default.GetString(result);

You'll need the following usings:

using System.IO.Compression;
using System.IO;

Then you can pass your JSON text to the compressor like this:

// compress text
byte[] compressedResult = Compress(resultSet);

And you'll need to decompress back into JSON before deserializing:

// decompress text
string resultSet = Decompress(compressedResult);

Where to Get the Code

As usual, you can go to my GitHub account and download the projects by clicking here.