Categories
My Media System Programming

It’s all the little things

Having been coding in c# for some time now, what is really nice about the language compared to c++ is the foreach statement. The syntax is really natural and easy to read:

     foreach (string s in strings)

Compare this to the standard c++ notation:

     for (vector::const_iterator i = strings.begin(),
             iend = strings.end(); i != iend; ++i)

So I decided there must be something easier and vague remembered that boost had something for this. And low and behold they had. So now instead of writing that horrible for line, one can just write:

     foreach (const string& s, strings)

It’s not quite as nice as i c# since one can’t have a pair on the leftside of the comma, so one needs to be using typedefs to fix that. And one must also remember the & as to not create unneeded copies of the string.

And the best part is that it’s written as a bunch of templates and macro’s so one can just include a header and of it goes. Doesn’t even have to change the Makefile 🙂

I’ve converted the whole MMS 1.1.0 code base to the new syntax and it’s really so much easier to read. Especially because I tend to use better names for the loop variable than i 🙂

Categories
My Media System profiling Programming

MMS now environmentally friendly

Sometimes nice tools just come dumping down from the sky and PowerTOP is the latest of such programs. The Linux kernel 2.6.21 has become tickless which means that instead of waking up at specific intervals it will just sleep until it needs to do something next. This clearly has the potential to save quite a lot of power, but only if it really can sleep longer than it otherwise would have.

Intel has created a tool, PowerTOP, to test which programs causes the kernel to wake up. And thanks to the power of free software they have also been able to fix quite a lot of the programs people use a lot. So tonight I decided that I would run MMS and see how it performed. I installed the new kernel and the tool on my laptop and was ready to test. Initially the kernel was waking up between 60-80 times a second but after starting MMS it quickly rose to 1000! Something was definitely wrong. After a long debug session I finally found the cause of this massive spike in kernel wakeups: SDL. For some reason SDL was initialized using SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER). This small SDL_INIT_TIMER flag caused SDL to start a thread which just slept for 10ms, woke up, just to sleep for 10ms again over and over again…

Luckily the fix was easy and now MMS causes no mentionable extra wake ups 🙂

Categories
.net On the web Programming

Interesting video on the future of programming

I found this interesting video today. It’s basicly just Anders Hejlsberg, Herb Sutter, Erik Meijer and Brian Beckman sitting around a table discussing future and current trends of programming languages. It touches a lot of exciting subject such as concurrency and the .Net’s ability to mix several programming languages.

It was very relieving that a lot of what was taught in courses at the university where I studied is now reaching mainstream languages 🙂