Showing tag results for Code

Jun 5, 2006
Post comments count0
Post likes count0

Why can't you say </script> in a script block?

Raymond Chen

Because it ends the script block, of course. Duh, what's so hard about that? Because if you have script that generates script, you'll find yourself caught out if you're not careful. For example, you can't say in a script block because the HTML parser will see the and conclude that your script block is over. In other words, the script block ...

Code
Jun 2, 2006
Post comments count0
Post likes count1

What does the CS_CLASSDC class style do?

Raymond Chen

Last time, I talked about the historical background for the class style and why it starts out sounding like a good idea but when you think about it some more turns out to be an awful idea. The class style is the same thing, but worse, for it takes all the problems of and magnifies them. Recall that the class style instructs the window manage...

CodeHistory
Jun 1, 2006
Post comments count0
Post likes count2

What does the CS_OWNDC class style do?

Raymond Chen

Recall that window DCs are most commonly used only temporarily. If you need to draw into a window, you call or, if outside of a paint cycle, , although painting outside of a paint cycle is generally to be avoided. The window manager produces a DC for the window and returns it. You use the DC, then restore it to its original state and return it to...

CodeHistory
May 24, 2006
Post comments count0
Post likes count1

Beware the C++ implicit conversion

Raymond Chen

Today's topic was inspired by a question from a customer: I am working on a stack overflow bug. To reduce the size of the stack frame, I removed as many local variables as I could, but there's still a a lot of stack space that I can't account for. What else lives on the stack aside from local variables, parameters, saved registers, and the retur...

Code
May 22, 2006
Post comments count0
Post likes count2

How do I write a regular expression that matches an IPv4 dotted address?

Raymond Chen

Writing a regular expression that matches an IPv4 dotted address is either easy or hard, depending on how good a job you want to do. In fact, to make things easier, let's match only the decimal dotted notation, leaving out the hexadecimal variant, as well as the non-dotted variants. For the purpose of this discussion, I'll restrict myself to the...

Code
May 19, 2006
Post comments count0
Post likes count1

Redirecting output can result in altered program behavior

Raymond Chen

Consider a program whose output to the console goes like this. (I've prefixed each line with the output stream.) You want to capture both the normal and error streams, so you run the program and append "" to capture both streams into a single file. But when you look at the resulting output file, you get this: What happened? Most programs c...

Code
May 16, 2006
Post comments count0
Post likes count0

The real scoop on the the x64 calling convention on 64-bit Windows

Raymond Chen

Official (though preliminary) documentation on the x64 calling convention is available on MSDN, for those who want more than my quack overview. (Oops, I meant "quick overview". Little Freudian slip there.)

Code
May 3, 2006
Post comments count0
Post likes count1

The alertable wait is the non-GUI analog to pumping messages

Raymond Chen

When you are doing GUI programming, you well know that the message pump is the primary way of receiving and dispatching messages. The non-GUI analog to the message pump is the alertable wait. A user-mode APC is a request for a function to run on a thread in user mode. You can explicitly queue an APC to a thread with the function, or you can do ...

Code
May 2, 2006
Post comments count0
Post likes count1

A cache with a bad policy is another name for a memory leak

Raymond Chen

A common performance trick is to reduce time spent in the heap manager by caching the last item freed (or maybe the last few) so that a subsequent allocation can just re-use the item rather than having to go make a new one. But you need to be careful how you do this or you can end up making things worse rather than better. Here's an example motiva...

Code
May 1, 2006
Post comments count0
Post likes count2

What's so special about bitmaps and DCs?

Raymond Chen

You can select pens, brushes, fonts and bitmaps into a DC with the function, and from this list, bitmaps are special. Because, if you look carefully, bitmaps are the only modifiable objects on the list. Pens, brushes and fonts cannot be modified once they are created. But bitmaps, oh, bitmaps. A bitmap selected into a DC changes as you draw into ...

Code