Showing tag results for Code

Feb 1, 2006
Post comments count0
Post likes count0

The per-class window styles and things really are per-class

Raymond Chen
Raymond Chen

Earlier, I discussed which window style bits belong to whom. One detail of this that I neglected to emphasize is that since the lower 16 bits of the window style are defined by the class, you can't just take styles from one class and apply them to another. For example, you can't create a button control and pass the style expecting to have the te...

Code
Jan 27, 2006
Post comments count0
Post likes count0

Waiting for all handles with MsgWaitForMultipleObjects is a bug waiting to happen

Raymond Chen
Raymond Chen

The and functions allow you to specify whether you want to want for any or all of the handles (either by passing or by passing , accordingly). But you never want to wait for all handles. Waiting for all handles means that the call does not return unless all the handles are signalled and a window message meeting your wake criteria has arrived. S...

Code
Jan 26, 2006
Post comments count0
Post likes count1

Pumping messages while waiting for a period of time

Raymond Chen
Raymond Chen

We can use the function (or its superset ) to carry out a non-polling "sleep while processing messages". This function pumps messages for up to milliseconds. The kernel of the idea is merely to use the function as a surrogate for , pumping messages until the cumulative timeout has been reached. There are a lot of small details to pay heed to...

Code
Jan 25, 2006
Post comments count0
Post likes count0

You can call MsgWaitForMultipleObjects with zero handles

Raymond Chen
Raymond Chen

There is no function, but you can create your own with the assistance of the function. To wait for a message with timeout, we use the in a vacuous sense: You pass it a list of objects you want to wait for, as well as a timeout and a set of queue states, asking that the function return when any of the objects is signalled or when a message is...

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