2009-01-21

Mono 2.2

Recently Mono 2.2 was released. It has a bunch of new stuff, one of them is: SIMD (Single Instruction, Multiple Data) support in Mono.

Miguel de Icaza has a blog entry where he describes the new SIMD support in Mono. He has ported to C# a C++ application, to illustrate the new SIMD stuff, and then he compares the results, the C++ program was rather slow. I had a look at the source code an I've seen that the C++ program was compiled in debug mode.

I've decided to make a few tests for myself. I've used MinGW 4.3.2 and Visual Studio 2005, the tests where run on my Intel Mobile Core 2 Duo T7500.

Here are the results (in seconds):



The parameters for the above results were:



Mono is not quite there yet (at least on Windows).

I had to change the timing code for the C++ code, glib::GTimer is not a very good option on Windows. I've used the high-resolution performance counter, the code is presented below:


#ifndef PERFTIMER_H
#define PERFTIMER_H

#include <windows.h>
#include <string>

#include <iostream>
#include <iomanip>
#include <sstream>

class PerfTimer
{
     LARGE_INTEGER start_;

     LARGE_INTEGER stop_;
     LARGE_INTEGER freq_;
   public:
    
     PerfTimer()
     {
       QueryPerformanceFrequency(&freq_);
     }

    
     void Start()
     {
       QueryPerformanceCounter(&start_);
     }
    
     void Stop()

     {
       QueryPerformanceCounter(&stop_);
     }
    
     std::string ToString()
     {
       const int precision = 10000000;

       unsigned long time = static_cast<unsigned long>(
     (stop_.QuadPart - start_.QuadPart) * precision /
     freq_.QuadPart);
      
       std::ostringstream os;

       os << std::setfill('0');
       os << std::setw(2) << time / precision / 3600 << ":";
       os << std::setw(2) << time / precision % 3600 / 60 << ":";

       os << std::setw(2) << time / precision % 60 << ".";
       os << std::setw(7) << time % precision;
       os << std::setfill(' ');

      
       return os.str();
     }
};

#if 0
int main()
{
   PerfTimer timer;
   timer.Start();

   Sleep(1250);
   timer.Stop();
  
   std::cout << "Time: " << timer.ToString() << std::endl;
  
   return 0;
}

#endif

#endif // PERFTIMER_H




There are a few things I would like to point out about the Mono 2.2 Windows installer.

1. The executable is not digitally signed by Novell.



2. The graphics are hideous, 16 colors dithering? why? Is anybody in their right mind running Windows in 16 colors?


2009-01-18

Windows CE

I've been busy with the port to Windows CE of libogg, libvorbis, libflac. This is only the beginning, there is still allot of work remaining.

Also I've done a bit of restructuring, I've reduced the number of binaries from 30 to 20, by changing from dynamic link libraries to static libraries. I've changed the usage of the CRT, from dynamic to static linking, this has increased the size of the binaries but overall the installer has the same size, thanks to LZMA solid compression :-)

The above changes will ease the usage of the libraries, for example only dsfOggDemux2.dll dsfVorbisDecoder.dll are needed for Vorbis decoding.

I have created my first Windows CE "Hello World" program. I've wanted for a long time to do that. I've learned that Windows CE has only Unicode support, no more multi byte nightmare.

Because you don't have a console attached the classical "Hello World" is a bit different, a bit WIN32 APIsh:


#include <windows.h>

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd )
{
    
wchar_t message[] = L"Goodbye cruel adventure world!";
    
wchar_t caption[] = L"Monkeys are listening";

    ::
MessageBox(0, message, caption, MB_OK | MB_ICONINFORMATION);
    
    
return 0;
}



If you try to run an executable which is not digitally signed, you are being prompted by the operating system telling you that it's dangerous to run "unknown" software.

Since I have a certificate from CERTUM I have signed the executable, but still the prompt was there. The problem was that my telephone doesn't have the root certificate from CERTUM installed. I've went to CERTUM's root certificate page and taken the "Public Key of Certum Level II", installed it and my program ran without any prompts from the operating system.

And now the mandatory "screen shot":

2009-01-15

Programming -- Principles and Practice Using C++

Is the name of Bjarne Stroustrup's latest book.

Here is a quote for the book's website:
It is designed for classroom use, but written with an eye on self study. Drafts have been used as the basis for first programming classes for electrical engineer, computer engineer, and computer science students at Texas A&M University for three years now.

The first thing that you notice when you open the book it's the color! The book is colored, and it has lots of pictures! You can notice that also in the sample chapters found on the book's website :)

My guess is that it was the author's intention to make it more appealing for the students, having to read more than 1000 black and white pages can have a devastating effect on a student's pathos!

This is the second colored programming book that I have, after "Windows Presentation Foundation Unleashed".

This is Bjarne's first book about graphical user interface (GUI) applications development. He had chosen FLKT as a GUI library, and there are four chapters allocated (~160 pages).

I can't say anything more because I haven't read it, but I can attach a picture:

2009-01-12

OptiPNG

When it comes to saving screen shots, PNG is the number one image format due to its lossless compression.

JPEG has artifacts around text and washed colors because of lossy compression, GIF has a limited color palette (only 256 distinct colors).

Normally PNG files a bit bigger than JPEG and GIF, but with OptiPNG you can decrease the size of a PNG file quite a bit.

I have taken a screen shot of vorbis.com and saved it under different file formats:
  • BMP - 2.956.854 bytes
  • PNG - 130.174 bytes (IrfanView level 9 compression)
  • PNG - 115.491 bytes (Microsoft Paint)
  • JPEG - 99.003 bytes (80% compression)
  • GIF - 90.024 bytes
  • PNG - 88.040 bytes (OptiPNG on Microsoft Paint's PNG file)
  • PNG - 87.967 bytes (OptiPNG on IrfanView's PNG file)

OptiPNG has been created by Cosmin Truţa, yet another famous Romanian computer science engineer star

2009-01-06

XAML in native C++

With the advent of WPF and XAML Microsoft has changed the way GUI Windows applications are developed, by introducing markup language into GUI development.

Unlike previous GUI APIs, the core of the WPF is written entirely in managed code, there is nothing for native C++ developers, there is not even support for C++/CLI (one can do some workarounds, but no support from the IDE and Blend)

Today I have found out that CodeJock has added support (see press release) for XAML scripts in their Xtreme ToolkitPro library. They do not support everything from WPF, they started adding markup properties for various GUI elements, in time the support will continue to grow.

The XAML section of their forums contains lots of information on the topic, which stuff is working, which is not. There I have found out sample applications, an early version of their MarkupPad (now an year old), which shows the capability of their XAML parser.

I have made a screenshot with MarkupPad and XAMLPad:



They both look the same, then I have had a look with Process Explorer and here is another picture with the results (see memory footprint):



I am aware that the comparison is not fair, CodeJock doesn't have a full XAML parser (no Timeline, no 3D, no...), but these are facts which can be seen at the moment.

Hats off for CodeJock for adding this functionality, I guess Microsoft could have done the same for MFC, but they don't care anymore about native GUI development, the latest new blood in MFC was bought from BCGSoftware, which doesn't have any support for XAML in their flagship products, namely BCGControlBar

It would be nice to have an open source, cross platform, native C++ XAML parser.

2009-01-04

Python has a bin

I mainly use Python on Windows as a calculator. I can use expressions, variables, and it can handle really big numbers.

When I need to transform decimals into hexadecimal I use hex(number) function. On many occasions I've tried bin(number) and failed because until Python 2.6 there was no bin function, it took me some time to realize why it worked :) then I've read Python 2.6 change log.

Python 2.6 is cooler now with the bin function!