Showing tag results for Code

Dec 8, 2009
Post comments count0
Post likes count1

How do I determine the processor's cache line size?

Raymond Chen

When doing high-performance computing, you need to worry about the CPU cache line size in order to avoid issues like false sharing. But how can you determine the processor's cache size? The function will give you characteristics of the logical processors in use by the system. You can walk the returned by the function looking for entries of type...

Code
Dec 2, 2009
Post comments count0
Post likes count1

A shell extension is a guest in someone else's house; don't go changing the carpet

Raymond Chen

A customer was running into this problem with a shell extension: I am writing a shell namespace extension. I need to get data from a COM server, which requires impersonation via with . As I am just writing an extension into , I am not able to call , anymore from my extension. Is there a way I can start by setting in its COM initialization? I w...

Code
Nov 25, 2009
Post comments count0
Post likes count1

How do I get the command line of another process?

Raymond Chen

Win32 doesn't expose a process's command line to other processes. From Win32's point of view, the command line is just a conveniently initialized parameter to the process's startup code, some data copied from the launching process to the new process and forgotten. We'll get back to the Win32 point of view a little later. If you look around in W...

Code
Nov 20, 2009
Post comments count0
Post likes count1

The difference between assignment and attachment with ATL smart pointers

Raymond Chen

Last time, I presented a puzzle regarding a memory leak. Here's the relevant code fragment: The problem here is assigning the return value of to a smart pointer instead of attaching it. The function creates a memory stream and returns a pointer to it. That pointer has a reference count of one, in accordance with COM rules that a function ...

Code
Nov 19, 2009
Post comments count0
Post likes count1

We're using a smart pointer, so we can't possibly be the source of the leak

Raymond Chen

A customer reported that there was a leak in the shell, and they included the output from Application Verifier as proof. And yup, the memory that was leaked was in fact allocated by the shell: On the other hand, is an object creation function, so it's natural that the function allocate some memory. The responsibility for freeing the memory be...

Code
Nov 13, 2009
Post comments count0
Post likes count0

What a drag: You can be a drag in managed code, too

Raymond Chen

David Anson digests my earlier series on virtual drag/drop and translates it into managed code. His example of dragging his entire RSS feed is an excellent illustration of dragging dynamically-generated virtual content. (I didn't use an example like that because the purpose of the What a drag series was to get something done in the least amount...

CodeWhat a drag
Nov 11, 2009
Post comments count0
Post likes count1

Trying to avoid double-destruction and inadvertently triggering it

Raymond Chen

We saw some time ago the importance of artificially bumping an object's reference count during destruction to avoid double-destruction. However, one person's attempt to avoid this problem ended up triggering it. The explanation for the line was that it was done to avoid the double-destruction problem if the object receives a temporary during...

Code
Nov 9, 2009
Post comments count0
Post likes count1

How do I create a toolbar that sits in the taskbar?

Raymond Chen

Commenter Nick asks, "How would you go about creating a special toolbar to sit on the taskbar like the Windows Media Player 10 minimised toolbar?" You would look at the DeskBand API SDK Sample in the Windows Platform SDK. The magic word is DeskBand. This MSDN page has an overview. Bonus chatter: I've seen some online speculation as to whether ...

Code
Nov 6, 2009
Post comments count0
Post likes count1

Signs that the symbols in your stack trace are wrong

Raymond Chen

One of the things programmers send to each other when they are trying to collaborate on a debugging problem is stack traces. Usually something along the lines of "My program does X, then Y, then Z, and then it crashes. Here is a stack trace. Can you tell me what's wrong?" It helps if you at least glance at the stack trace before you send it, bec...

Code