Saturday, March 20, 2010

Difference between malloc and calloc

One of the most basic things a person familiar with programming language 'C' is supposed to know is:
What is the difference between the malloc and the calloc function calls?
Query Google and it'll tell you how many folks are interested in the answer to this question. The reason for that is that it is one of the most commonly asked questions in job interviews at the beginner's level.

Since the readers here may not possess that familiarity, the answer that's usually expected is:
While both the functions allocate memory, calloc() additionally initializes all the locations in the newly allocated memory block to '0'.
That's that. That answer is sufficient for the interview. That's all I knew. Until now.

I was reading The Old New Thing today and there was a mention of Copy-on-Write (CoW) in one of the posts. To understand it better, I decided to read about CoW on Wikipedia. From the Wikipedia page, I found out that calloc can be implemented using CoW:
Another use is in the calloc function. This can be implemented by having a page of physical memory filled with zeroes. When the memory is allocated, the pages returned all refer to the page of zeroes and are all marked as copy-on-write. This way, the amount of physical memory allocated for the process does not increase until data is written.
Nice, I said to myself. Note taken. Thanks TONT, Wikipedia!

Tuesday, February 16, 2010

John Gruber, we expect better posts from you.

On Monday, February 15, 2010, Microsoft announced their new platform for mobile devices, Windows Phone 7 Series. This was at the Mobile World Congress in Barcelona, Spain. The internet, since then, has been full of positive reviews of the platform.

Being one of those guys who got an early preview of the platform, I can tell you that it is a very good effort. Not better than the best out there, but certainly an impressive effort.

However, John Gruber, on his popular blog Daring Fireball, has this to write about it:
What a great product name. Not a mouthful at all.
Yes, we know it is not such a good name, but instead of just saying that, you could have at least said a couple of things about the platform, good or bad. Positive reviews encourage the folks building it and bad reviews highlight the areas to improve. It also makes for an article worth reading.

Over the years you have written lots of good posts; this one isn't one of them. We have come to expect better from you. Please do not let us down.

Saturday, February 06, 2010

Trying out the email interface

blogger.com (or blogspot.com) provides the blog owners with the ability to publish posts to their own blogs by sending an email to an email address, part of which is chosen by the blogger herself.
I know it has been around for a while, but I haven't tried it prior to this.

One of the things I want to try out is its ability to handle rich text, i.e. bold, italics, colors, highlighting.

Then there's quoted text.

How about the following:
  1. Ordered list
  2. ...
What happens if I include unordered list, such as this one:
  • Unordered item #1
Let's find out how good/ugly looking this one turns out to be.