Showing tag results for Code

Jan 24, 2006
Post comments count0
Post likes count0

Performance consequences of polling

Raymond Chen
Raymond Chen

Polling kills. A program should not poll as a matter of course. Doing so can have serious consequences on system performance. It's like checking your watch every minute to see if it's 3 o'clock yet instead of just setting an alarm. First of all, polling means that a small amount of CPU time gets eaten up at each poll even though there is nothing ...

Code
Jan 23, 2006
Post comments count0
Post likes count0

If your callback fails, it's your responsibility to set the error code

Raymond Chen
Raymond Chen

There are many cases where a callback function is allowed to halt an operation. For example, you might decide to return to the message to prevent the window from being created, or you might decide to return to one of the many enumeration callback functions such as the callback. When you do this, the enclosing operation will return failure bac...

Code
Jan 19, 2006
Post comments count0
Post likes count0

The cost of trying too hard: String searching

Raymond Chen
Raymond Chen

There are many algorithms for fast string searching, but the running of a string search is inherently O(n), where n is the length of the string being searched: If m is the length of the string being searched for (which I will call the "target string"), then any algorithm that accesses fewer than n/m elements of the string being searc...

Code
Jan 18, 2006
Post comments count0
Post likes count0

The cost of trying too hard: Splay trees

Raymond Chen
Raymond Chen

Often, it doesn't pay off to be too clever. Back in the 1980's, I'm told the file system group was working out what in-memory data structures to use to represent the contents of a directory so that looking up a file by name was fast. One of the experiments they tried was the splay tree. Splay trees were developed in 1985 by Sleator and Tarjan as a ...

Code
Jan 16, 2006
Post comments count0
Post likes count0

Understanding what things mean in context: Dispatch interfaces

Raymond Chen
Raymond Chen

Remember that you have to understand what things mean in context. For example, the IActiveMovie3 interface has a method called get_MediaPlayer. If you come into this method without any context, you might expect it to return a pointer to an IMediaPlayer interface, yet the header file says that it returns a pointer to an IDispatch interface instead. ...

Code
Jan 6, 2006
Post comments count0
Post likes count0

Why do image lists and tool bars use horizontal strips if vertical is so much better?

Raymond Chen
Raymond Chen

Two people pointed out that the function and toolbars use horizontal strips even though we learned that vertical strips are much more efficient. While it's true that the images are passed to the and functions in horizontal strips, the image list and toolbar code copy them to a vertical strip. In other words, the horizontal strip is merely an...

Code
Jan 5, 2006
Post comments count0
Post likes count0

Converting between LCIDs and RFC 1766 language codes

Raymond Chen
Raymond Chen

Occasionally, I see someone ask for a function that converts between LCIDs (such as 0x0409 for English-US) and RFC 1766 language identifiers (such as "en-us"). The rule of thumb is, if it's something a web browser would need, and it has to do with locales and languages, you should look in the MLang library. In this case, the IMultiLanguage:...

Code
Jan 4, 2006
Post comments count0
Post likes count0

Taxes: Detecting session state changes, such as a locked workstation

Raymond Chen
Raymond Chen

Another developer tax is playing friendly with Fast User Switching and Terminal Services. When the workstation is locked or disconnected, you should turn off non-essential timers, minimize background activities, and generally send your program into a quiet state. If you already used the technique of painting only when your window is visible on th...

Code