[Gc] Changes requested to reduce GC heap growth on Windows

Andrew Begel abegel at eecs.berkeley.edu
Tue Jan 27 10:01:00 PST 2004


If this is true, then the docs pages for MSDN Visual Studio.NET  
description of C and C++ are incorrect, and it's a bug in the MSFT  
compiler. If your empirical observation is correct, maybe there's a  
compiler flag being passed on Windows (or not being passed) that is  
controlling this behavior that could be fixed.

Andrew

 From the C++ manual online (the same deal about short-circuit eval is  
true about the C language reference as well. It's defined in the C  
standard as well as the MS docs).

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ 
vccelng/htm/express_42.asp

Logical AND Operator

The logical AND operator (&&) returns the integral value 1 if both  
operands are nonzero; otherwise, it returns 0. Logical AND has  
left-to-right associativity.

Syntax
logical-and-expression :
inclusive-or-expression
logical-and-expression && inclusive-or-expression

The operands to the logical AND operator need not be of the same type,  
but they must be of integral or pointer type. The operands are commonly  
relational or equality expressions.

The first operand is completely evaluated and all side effects are  
completed before continuing evaluation of the logical AND expression.

The second operand is evaluated only if the first operand evaluates to  
true (nonzero). This evaluation eliminates needless evaluation of the  
second operand when the logical AND expression is false. You can use  
this short-circuit evaluation to prevent null-pointer dereferencing, as  
shown in the following example:
char *pch = 0;
...
(pch) && (*pch = 'a');


If pch is null (0), the right side of the expression is never  
evaluated. Therefore, the assignment through a null pointer is  
impossible.

and from the C reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ 
vccelng/htm/expre_9.asp

C Sequence Points

Between consecutive sequence points an objects value can be modified  
only once by an expression. The C language defines the following  
sequence points:
	• 	Left operand of the logical-AND operator (&&). The left operand of  
the logical-AND operator is completely evaluated and all side effects  
complete before continuing. If the left operand evaluates to false (0),  
the other operand is not evaluated.
	• 	Left operand of the logical-OR operator (||). The left operand of  
the logical-OR operator is completely evaluated and all side effects  
complete before continuing. If the left operand evaluates to true  
(nonzero), the other operand is not evaluated.


On Jan 26, 2004, at 8:18 PM, Derek McUmber wrote:

> Attached is a small diff of required changes for gc compiled with the  
> MSFT family of C compilers.  Please review this request and check for
> correctness.  I have tested this on WinXP/2K/2KAdvanced/win98 and it
> appears to be satisfactory.
>
> The issue is with statements like:
>
> 	while ( 0 == h && GET_MEM()) {
> 		h = GC_allochblk(...);
> 	}
>
> The microsoft compilers do not optimize the execution by not calling
> the right side of the && expression if the left side is true (vc98 and
> vc7).  This leads to double heap growth which is not desirable.
>
> thanks



More information about the Gc mailing list