Showing results for May 2005 - Page 2 of 3 - The Old New Thing

May 20, 2005
0
0

When is a window visible yet not visible?

Raymond Chen
Raymond Chen

Today, a quick puzzler. Consider the following code fragment: We just showed the window, certainly it is visible, right? Yet the assertion can fire (even in the absence of multi-threading). Why? Answer below - stop reading if you want to try to solve it yourself. Take a look at the function. If the specified windo...

Code
May 18, 2005
0
0

Loading the dictionary, part 5: Avoiding string copying

Raymond Chen
Raymond Chen

Looking at the profile for our program so far, 35% of the CPU time is spent copying strings around. Let's see if we can improve that. The best way to speed up copying strings is not to copy them in the first place. Using a in our structure forces the class to copy the string data, when all we really need to copy is the pointer and size infor...

Code
May 17, 2005
0
0

You can't escape those AOL CDs

Raymond Chen
Raymond Chen

One of my colleagues was unpacking one of those $30,000 quad-processor more-memory-than-you-know-what-to-do-with super-server computers. The kind that require their own electrical substation. And it came with an AOL CD. It's like buying a Lexus and finding a 35-cents-off coupon in the glove compartment. Apparently, one of the questions AOL tech ...

Other
May 16, 2005
0
0

Loading the dictionary, part 4: Character conversion redux

Raymond Chen
Raymond Chen

Getting rid of was a big help, but 480ms is still not quite peppy enough. You need to respond to user actions within a tenth of a second for thing to seem responsive. Profiling the latest endeavor reveals that 40% of our CPU time is spent in . Some debugging reveals that ultimately calls but uses it to convert only one or two characters at ...

Code
May 13, 2005
0
0

Loading the dictionary, part 3: Breaking the text into lines

Raymond Chen
Raymond Chen

Even after moving the character conversion out of the function, profiling reveals that is still taking nearly 50% of our CPU. The fastest code is code that isn't there, so let's get rid of altogether. Oh wait, we still need to break the file into lines. But maybe we can break the file into lines faster than did. This very simple class baby...

Code
May 12, 2005
0
0

The Microsoft corporate network: 1.7 times worse than hell

Raymond Chen
Raymond Chen

Today I'm going to tell a story from 1996. Why? Because I can. One of the tests performed by Windows Hardware Quality Labs (WHQL) was the NCT packet stress test which had the nickname "Hell". The purpose of the test was to flood a network card with an insane number of packets, in order to see how it handled extreme conditions. It uncovered packe...

History
May 11, 2005
0
0

Loading the dictionary, part 2: Character conversion

Raymond Chen
Raymond Chen

When you want to optimize a program, you first need to know where the time is being spent. There's no point optimizing a function that isn't actually responsible for your poor performance. For example, if a particular function is responsible for 2% of your CPU time, then even if you optimized it down to infinite speed, your program would spee...

Code
May 10, 2005
0
0

Loading the dictionary, part 1: Starting point

Raymond Chen
Raymond Chen

The first thing we'll need to do in our little dictionary program is to load the dictionary into memory. The format of the dictionary file is as a plain text file, each line of which is of the form Since it was the Big5 dictionary we downloaded, the Chinese characters are in Big5 format, known to Windows as code page 950. Our program will be U...

Code
May 9, 2005
0
0

Developing a Chinese/English dictionary: Introduction

Raymond Chen
Raymond Chen

The other day, one of my colleagues mentioned that his English name "Ben" means "stupid" in Chinese: 笨/bèn/ㄅㄣˋ. (His wife is Chinese; that's why he knows this in the first place.) Knowing that the Chinese language is rich in homophones, I fired up my Chinese/English dictionary program to see if we could find anythin...

Code