Archive for the ‘C++’ Category

Using usertype.dat as spell checker

Sunday, November 15th, 2009

There are thousands of classes, structure, functions and constants in the Windows library and it’s often hard to remember the right spelling. Here’s a simple trick to use the usertype.dat as a very simple spell checker.

Usertype.dat?
First, usertype.dat is a file which can be configured in the MS IDE (see help file, because it differs with the versions). Simply activate it and use my usertype.dat as a start. It contains almost 4000 key words from the libraries.

When you now type one of these key words right, it will be displayed in a different color (I prefer gray – to emphasize that I don’t have to pay attention here). Here’s how it can look like.

Example:

Note that all the common things like HICON, LoadImage or LR_DEFAULTCOLOR are written in gray because they’re spelled correct. And other words (variables in this case) like hIcon and IconId1 a printed in white because they’re not predefined. If I had written Load_Image (instead of LoadImage), it would have been printed in white, too, and I know that it might be incorrect.

Dangerous QuickSort

Friday, May 15th, 2009

When it comes to sorting, QuickSort is an all-time-favourite (so I though) and I chose it for implementing a sortable list with data. In some cases (when there were on few changes), it didn’t perform well, to I switched to an old-fashioned bubble-sort in such cases.

What I had to learn now, is that if the data that has to be sorted, is arranged in the right / unfortunate way, then QuickSort can easily crash your program by consuming excessively stack space and finally causing a stack overflow. You won’t need much data for this. 10,000 items is enough to perform terribly slow and finally crashing the software.

I switched to IntroSort, which seams to work better (so far) and (according to Wikipedia) behaves better in worst-scenarios than QuickSort. We’ll see. Sample implementations for IntroSort are rare, but I found one linked in this blog.