Showing tag results for Code

Sep 15, 2006
Post comments count0
Post likes count0

Allocating and freeing memory across module boundaries

Raymond Chen
Raymond Chen

I'm sure it's been drilled into your head by now that you have to free memory with the same allocator that allocated it. matches , matches , matches . But this rule goes deeper. If you have a function that allocates and returns some data, the caller must know how to free that memory. You have a variety of ways of accomplishing this. One is to s...

Code
Sep 13, 2006
Post comments count0
Post likes count0

Philosophical discussion on when to mark a method as virtual

Raymond Chen
Raymond Chen

When should you mark a method as virtual? This question has both a technical and a philosophical aspect. The technical aspect is well-understood: You mark a method as virtual if you want calls to the method to be invoked on the run-time type of the invoked object rather than on the compile-time type of the invoking reference. But there is a heavy...

Code
Sep 8, 2006
Post comments count0
Post likes count0

Const pointers: Logical consequences

Raymond Chen
Raymond Chen

Consider this follow-up question to the question from last time: When I call the function, can I assume that the field of the structure will not be modified? If we take a look at the declaration of the function, we see that it reads like this: Go past all the function declaration specification goo and look at the parameter list. It's a ...

Code
Sep 7, 2006
Post comments count0
Post likes count0

You have to free memory with the same allocator that allocated it: Logical consequences

Raymond Chen
Raymond Chen

Everybody should know by now that you have to free memory using the same allocator that you used to allocate the memory. If you allocate with then you have to free with ; if you allocate with then you have to free with . Once you've internalized this rule, you can use it to draw other logical conclusions. Consider: When I call the function, wh...

Code
Sep 6, 2006
Post comments count0
Post likes count0

You already know what your target architecture is (or at least you should)

Raymond Chen
Raymond Chen

Sometimes the questions I see make me shake my head in wonderment. How do I determine programmatically what processor architecture my program was compiled for? I want the x86 version of my program to behave differently from the ia64 version. Is there some API I can call? Note that this person isn't asking whether the program is running on 64-...

Code
Sep 1, 2006
Post comments count0
Post likes count0

On the unanswerability of the maximum number of user interface objects a program can create

Raymond Chen
Raymond Chen

The answer to the question "What is the maximum number of window classes a program can register?" is not a number. Most user interface objects come from a shared pool of memory known as the "desktop heap". Although one could come up with a theoretical maximum number of window classes that can fit in the desktop heap, that number is not achievable ...

Code
Aug 31, 2006
Post comments count0
Post likes count0

The dialog class goes under the sneaky name WC_DIALOG

Raymond Chen
Raymond Chen

An anonymous commenter wanted to know how to create a dialog box with . The window class for dialog boxes is . I'm not quite sure why anybody would want to create a dialog box this way, but there you have it.

Code
Aug 28, 2006
Post comments count0
Post likes count2

Try to avoid having BOOL function parameters

Raymond Chen
Raymond Chen

Generally speaking, I believe that you should try to avoid giving functions a boolean parameter (, , etc.) unless the meaning of that boolean parameter is blatantly obvious. Examples of obvious meaning would be the second parameter to the function ( obviously means the window is being enabled and means that it's being disabled) and the final para...

Code