32 vs. 64-bits

There is often a great debate about whether their program should be compiled as 32 or 64-bit. People often think a program will run better on their 64-bit OS if it is 64-bit instead of 32-bit, but that is often not the case. In this post I will discuss some of the advantages and bottlenecks in a 32-bit program versus a 64-bit program.

Many people does not understand what it means that their program is n-bits compiled. (Where n can be 8, 16, 32, 64, and so on) It basically means how much memory your program can allocate. In 32-bits, we can allocate 232 bytes. In the 32-bit world, all objects pointers has 32 zeros and ones. For each bit, there is two posibillities. As there are 32 possible combinations, therefore 232 bytes. In the 64-bit world it would be 264 bytes. We would have the following mathematical formula: 2bits = total memory available to allocate. 

Let's say our program is 32-bit. As each byte in our memory would have a memory address of 32-bits, every pointer (object reference for C# and VB coders) will have the size of 32-bits (4 bytes). If we compiled our program as 64-bit, each pointer would be twice as big. To understand this better, let's look at an example:

C#:

struct Node
{
    Node l;
    Node r;
    int data;
}

C++:

struct Node
{
	Node* l, *r;
	int data;
}

(Struct is the same in both languages)

For a binary tree with n nodes in a x-bit program, the total size of the tree would be as following:

size = n(2x+32)

In our 32-bit program, we have 2540 nodes. This tree has then the size of 2540*(2*32+32) = 243840 bits (30KB).
Let's say we wanted to compile our program as 64-bit:  2540*(2*64+32) = 406400 bits (50KB). A memory increase of 60%. 

This is the most common case for all program which moves from 32 to 64-bits, a memory increase of 60%. As we would get larger objects, memory fragmentation would also occur more frequent. 

A 64-bit CPU as a larger register than a 32-bit CPU. This leads to some loops would run faster as the CPU would not have to fetch data from the memory or cache (Code from Wikipedia):

int a, b, c, d, e;
for (a=0; a<100; a++)
{
  b = a;
  c = b;
  d = c;
  e = d;
}

 

To summarize, compiling a program as 64-bit often does not lead to any significant performance improvement. However, if your program depends on heavy calculation such as cryptography or video rendering, there could be a noticeable gain. Unless your program is a Twitter client, a normal GUI application that does not do much than displaying data from a file or the web, 32-bit may be the way to go. However, if you are writing a driver, database, image processing software, codecs or games, 64-bit would be the better choice. For mobile devices, 32-bit would be the best option as 64 would require more memory and would therefore require more juice from your battery. Most smartphones does not require much more than 2-3GB of ram and we are not there yet to switch over to 64-bit mobile OSes.

The Xbox One - Back to the Past

I was really excited when the Xbox One was announced. One of the things I hoped for was that Microsoft had done something with those discs from the 90's. And they did, almost. What almost where to be a far better experience for users where thrown away by confused users mostly on the Internet in addition to Sony who made fun of Microsoft and their new model. Sony indirectly asked Microsoft why they would change the current model for games when the one they used where working perfectly fine. I would not say that is the question. What is the issues with the current model and what could be improved? 

Today we purchase a disc and put it into our console (It doesn't matter if it is PS or Xbox), we update/install it and we play the game. After a few years, the disc is barely readable. This is the case for several of the games I played in my childhood and I have ended up with discs that are barely readable. One example is the SimCity 3000 disc, which I am almost too scared to touch as the disc has been taken in and out of the disc-tray too many times. It is also the case for the Halo ODST disc which I bought used (!) from Gamestop. Another issue with the discs is that when people borrow your game, they have to return the game physically. This can become a headache for people who live far from each other. 

The current model is not "perfect". In the future, I expect companies to improve their products. "Wireless networks works perfectly today, and I see no reason to improve them" No, they do not work perfectly. Saying that something is perfect means you are too narrow minded to see the negative sides of something, and it is not a good thing when you are into tech and IT. 

One of the things I agree on is that you have to be online once each 24th hour. They could instead have been using one month, just like Spotify does instead, as people could take their console with them on vacation and want to play there but they don't have any internet and the story goes on. But on the other hand, is one time each 24th hour really a problem for that many people? Most people have a reliable connection enough to play multiplayer games, but the only issue I see with it is if you travel a lot and take their xbox with them. But honestly, I personally like not being connected while I am on vacation. 

 

If this is all about control, what about the future? And what just happened to movies and music? You buy a certain price per month and you can watch as much movies and listen to as much music as you like. You do not own any of the content as it is streamed from the web. I am thinking of the future, and I do not think unreliable, fragile and slow discs are the future. Sure, many people do not have a fast internet connection (yet), but this is something that comes with the future. I already have a 25/25Mbit connection, and I can rarely use half of it.

Should companies base their services on how the average consumer is, or how the market will evolve over a few years? It is this question which bothers me. Many people speak of the PS4 and XBone as the last consoles MS and Sony will release, but is this it? Really? Discs? 2013? What? Seriously? Let us look at this from a perspective point of view. The CD is from the 1980s. The DVD is from 1995 and Bluray is from the early 2000. They are light-weight, easy to make and can store a large amount of data. But how will this keep up with the future? Discs are unreliable as they can easily get scratches and break easily. This is the main reason why I mean discs does not fit into any of the next generation consoles. 

To sum it all up: Microsoft wanted to be a bit futuristic, they presented their stuff wrong and made some small mistakes with their model. The Internet doesn't like it and Sony takes advantage of it to make fun of Microsoft and get more users. Then Microsoft regrets and goes back to where they where in the beginning. We end up with the same console, upgraded hardware, a bit better software with a new features I won't be able to use (TV entertainment stuff, as I live in Norway) but nothing else. The same thing goes with Sony. Basically just a hardware upgrade and a new homescreen/dashboard. And what about DRM? Steam have been using DRM for a while now.