February 11th, 2008

An Extremely busy Week

This week seemed to be overrun with work and chores. While it was not bad in and of itself I had very little free time to do things, like say post once a day, or eat healthy. I need to use this as an opportunity to learn how to more efficiently manage my time.

Dead Poets

I got such a good response from my image of a dead poet two weeks ago I decided to make my image this week another dead poet. This time the dead poet is borne by a centaur as depicted by Gustave Moreau.

A C++ quiz

Suppose I gave you the following snippets of code:

#include <cstdio>

void Class::PrintFoo()
{
 printf("Foo\n");
}

int main()
{
   Class13 c13;

   c13.PrintFoo();
   c13->PrintFoo();

   return 0;
}

Now write me the code for Class13, so this would compile, run, and print "Foo" twice. So far 50% of the people I have interviewed have given me the correct answer. For those that have dealt with smart pointers this should be trivial, for everyone else consider that a hint.

C# OS

I just learned about Cosmos. An open source OS written almost entirely in C#. I haven't had a chance to really play with it, or even read that much about it, but the concept is intriguing, and I hope to get the time to play with it in the future. Along with the 10 million other things I want to waste my time one.

And yes I also learned of SharpOS at the same time, but since it uses the viral GPL. I refuse to link to it.

Another C++ puzzle

aroach figure this out almost immediately. Assume I have a multi threaded application with the follow code:
class A
{
public:
 A()
 {
    m_ = malloc(10);
 }
 ~A()
 {
   free(m_);
 }

private:
 void* m_;
};

void WorkerThread(void* v)
{
  A a;
  // Line 37
}


What could I place after the comment "// Line 37" to make the code leak 10 bytes of memory for every worker thread I created?