Author Topic: MSVC++ Optimization Observation  (Read 1990 times)

anphanax

  • Member
  • **
  • Posts: 197
  • Kudos: 11
    • http://june.tripod.com
MSVC++ Optimization Observation
« 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.

Pathos

  • Member
  • **
  • Posts: 518
  • Kudos: 416
Re: MSVC++ Optimization Observation
« Reply #1 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.

Pathos

  • Member
  • **
  • Posts: 518
  • Kudos: 416
Re: MSVC++ Optimization Observation
« Reply #2 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

Refalm

  • Administrator
  • Member
  • ***
  • Posts: 5,183
  • Kudos: 704
  • Sjembek!
    • RADIOKNOP
Re: MSVC++ Optimization Observation
« Reply #3 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)?

Pathos

  • Member
  • **
  • Posts: 518
  • Kudos: 416
Re: MSVC++ Optimization Observation
« Reply #4 on: 3 March 2006, 23:31 »
what is that supposed to mean?

H_TeXMeX_H

  • Member
  • **
  • Posts: 1,988
  • Kudos: 494
    • http://draconishinobi.50webs.com/
Re: MSVC++ Optimization Observation
« Reply #5 on: 4 March 2006, 03:01 »
No clue :D

Refalm

  • Administrator
  • Member
  • ***
  • Posts: 5,183
  • Kudos: 704
  • Sjembek!
    • RADIOKNOP
Re: MSVC++ Optimization Observation
« Reply #6 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:

Pathos

  • Member
  • **
  • Posts: 518
  • Kudos: 416
Re: MSVC++ Optimization Observation
« Reply #7 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++?