Showing tag results for Code

Feb 8, 2012
Post comments count0
Post likes count0

The path-searching algorithm is not a backtracking algorithm

Raymond Chen
Raymond Chen

Suppose your PATH environment variable looks like this: Suppose that you call intending to load the library at . If the network server is down, the call will fail. Why doesn't it just skip the bad directory in the PATH and continue searching? Suppose the function skipped the bad network directory and kept searching. Suppose that the code w...

Code
Feb 3, 2012
Post comments count0
Post likes count0

The compatibility constraints of error codes, episode 2

Raymond Chen
Raymond Chen

A customer reported an incompatibility in Windows 7: If A: is a floppy drive and they call and there is no disk in the drive, the call fails with the error . Previous versions of Windows failed with the error . Both error codes are reasonable responses to the situation. "The module couldn't be found because the drive is not ready." Programs...

Code
Jan 27, 2012
Post comments count0
Post likes count0

Does mapping the same shared memory two times in a process lead to double the address space usage?

Raymond Chen
Raymond Chen

A customer designed a system which uses shared memory. Specifically, for each database file, they create a corresponding shared memory block of, say, 200MB. Multiple clients which connect to the same database file use the same shared memory block. Naturally, if two processes each access the same database file, each process will map the shared memor...

Code
Jan 25, 2012
Post comments count0
Post likes count0

How do I disable the fault-tolerant heap?

Raymond Chen
Raymond Chen

A while back, I linked to a talk by Silviu Calinoiu on the fault-tolerant heap. But what if you don't want the fault-tolerant heap? For example, during program development, you probably want to disable the fault-tolerant heap for your program: If the program is crashing, then it should crash so you can debug it! Method 1 is to disable the ...

Code
Jan 23, 2012
Post comments count0
Post likes count0

Can OANOCACHE be used for non-debug purposes?

Raymond Chen
Raymond Chen

Friday asks whether OANOCACHE can be used for non-debug purposes, say to improve stability and/or speed. You can try, but it's not recommended. For one thing, it probably damages stability, because there are many applications out there which unwittingly rely on the BSTR cache to protect them from heap corruption bugs. The Windows team has for yea...

Code
Jan 18, 2012
Post comments count0
Post likes count0

Don't try to allocate memory until there is only x% free

Raymond Chen
Raymond Chen

I have an ongoing conflict with my in-laws. Their concept of the correct amount of food to have in the refrigerator is "more than will comfortably fit." Whenever they come to visit (which is quite often), they make sure to bring enough food so that my refrigerator bursts at the seams, with vegetables and eggs and other foodstuffs crammed into every...

Code
Jan 13, 2012
Post comments count0
Post likes count0

How do I print non-error messages during compilation?

Raymond Chen
Raymond Chen

Commenter Worf remarked, "My one wish is that would be supported." I always find it interesting when people say "I wish that Microsoft would stop following standards," since the directive is nonstandard. The Microsoft C/C++ compiler implements the feature in a method compatible with the standard, namely via a directive. If you want ...

Code
Jan 6, 2012
Post comments count0
Post likes count0

Why did HeapFree fail with ERROR_POSSIBLE_DEADLOCK?

Raymond Chen
Raymond Chen

A customer reported that they were receiving some assertion failures because the function was failing with what they believed to be a valid heap block, and the function reported that the reason for failure was . What's going on? One of my colleagues asked the psychic question, "Is the process exiting?" "Why yes, in fact it is. How did you know?...

Code
Jan 5, 2012
Post comments count0
Post likes count1

When DLL_PROCESS_DETACH tells you that the process is exiting, your best bet is just to return without doing anything

Raymond Chen
Raymond Chen

When the function receives a reason code of , the increasingly-inaccurately-named parameter to is used to indicate whether the process is exiting. And if the process is exiting, then you should just return without doing anything. No, really. Don't worry about freeing memory; it will all go away when the process address space is destroyed. Don...

Code