Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: anphanax on 3 March 2006, 07:17

Title: MSVC++ Optimization Observation
Post by: anphanax on 3 March 2006, 07:17
// Zero characters are repeated in compiled EXE.
char *value1 = "0", *value2 = "0";
char *value3 = "0", *value4 = "1";

// Zero character only appears once in data.
char *ZERO = "0"; char *ONE = "1";
char *value1 = ZERO, *value2 = ZERO;
char *value3 = ZERO, *value4 = ONE;

Is there a reason why duplicate string entries wouldn't be optimized and all point to the same data? Those character arrays shouldn't be editable in the first place (although they were in VC++ 5.0 and lesser), so i'm kind curious why that sort of optimization is absent. I know Java does it.

EDIT: Compiling in Release Mode, not Debug.
Title: Re: MSVC++ Optimization Observation
Post by: Pathos on 3 March 2006, 10:04
Are they in the same source file? How many other strings in the file are there?

I've played around in some executables and even common floating point numbers are reused.

There would not be any issues involving such optimisations.

I'll test gcc.
Title: Re: MSVC++ Optimization Observation
Post by: Pathos on 3 March 2006, 10:08
gcc does it:

#include

int main (int argc, char *argv[])
{
   char * a = "0";
   char * b = "0";
   
   std::cout << "a = " << ((int) a) << std::endl;
   std::cout << "b = " << ((int) b) << std::endl;
   
   return 0;
}


output:

a = 4199088
b = 4199088
Title: Re: MSVC++ Optimization Observation
Post by: Refalm on 3 March 2006, 12:51
Quote from: anphanax
// Zero characters are repeated in compiled EXE.
char *value1 = "0", *value2 = "0";
char *value3 = "0", *value4 = "1";

// Zero character only appears once in data.
char *ZERO = "0"; char *ONE = "1";
char *value1 = ZERO, *value2 = ZERO;
char *value3 = ZERO, *value4 = ONE;

Is there a reason why duplicate string entries wouldn't be optimized and all point to the same data? Those character arrays shouldn't be editable in the first place (although they were in VC++ 5.0 and lesser), so i'm kind curious why that sort of optimization is absent. I know Java does it.

EDIT: Compiling in Release Mode, not Debug.

Aren't those already pre-buffered in the framework (annoyingly so)?
Title: Re: MSVC++ Optimization Observation
Post by: Pathos on 3 March 2006, 23:31
what is that supposed to mean?
Title: Re: MSVC++ Optimization Observation
Post by: H_TeXMeX_H on 4 March 2006, 03:01
No clue :D
Title: Re: MSVC++ Optimization Observation
Post by: Refalm on 6 March 2006, 10:08
Quote from: Pathos
what is that supposed to mean?

Welcome to the wonderfull world of Microsoft Visual Studio .NET :rolleyes:
Title: Re: MSVC++ Optimization Observation
Post by: Pathos on 6 March 2006, 13:01
I assumed by C++ he meant good old MSVC 6.0

If it is .NET meh who knows...

The Java buffering or what ever had some rather ugly side affects and no real performance gain so I would agree with MS on this one if they chose against implementing it.

does C++ .Net use handles like C# ? Whats the difference between C++ .NET and C++?