简体   繁体   中英

Visual C++ 10 (aka 2010) compared to Visual C++ 9 (aka 2008)

Is there an online resource describing the changes in the code generation of VC10 compared to VC9 ?

I'm not talking about c++0x and other nice features (such as built-in static_assert ), neither the refined UI. What I need to know is how the generated code is expected to be different, due to optimizations, changes in structure member alignment and etc.

PS It's a MSVC 2010 express, for Win32

EDIT

I've built several projects using VC10, so now I have some comparison data. Overall I see a significant executable image size increase, about 15% compared to VC9, and 10% even compared to VC8.

I'm optimizing for speed, not for image size. So that strictly speaking that comparison is not fair. However I remember that VC9 compared to VC8 usually produced a bit smaller images, yet managed to squeeze even more performance. From the performance point of view the new code is pretty close to that of VC9 (indistinguishable in my tests).

Besides the code quality degradation (which I hope is not the case) I see the following potential reasons for larger images:

  • More aggressive overall speed optimizations (which lead to an only modest effect, at least in my case), such as aggressive loop unrolling and etc.
  • Additional data in the image due to some new features (such as SAFESEH, DEP and etc.)
  • Larger runtime libraries for whatever reasons (I'm using them as a static lib, linked into the executable)

Disabling the SAFESEH option (which is now on by default) decreases the image slightly (1%).

Any more ideas? May this be different if I use non-express version of VC10? Does enabling DEP (data execution prevention) enlarge the image size? (I guess - no)

I'm compiling with /EHa, this reduces optimization strength, but this is also the case with older VC versions.

EDIT 2

I've found the causes of the image bloating.

Using dumpbin I've discovered that surprisingly the EXE built by VC10 contains a relocation table . This was weird, since EXEs don't usually contain it. And it disappears if the EXE was built with the following in the vcxproj file:

<Link>
  <RandomizedBaseAddress>false</RandomizedBaseAddress>
</Link>

By default base address randomization is ON in VC10. This option mysteriously makes VC10's linker behave "as it builds a DLL", as the result it includes the relocation table.

This reduced the EXE size, but still not to the level of VC9. Then I've opened the EXE with dependencies walker, and discovered that the EXE built by VC10 imports EncodePointer and DecodePointer from kernel32.dll .

According to online resources, those functions are imported by the VC10 runtime libraries, by yet another idiotic naive attempt to enhance the software "security". Not only the new runtime seems fatter, but this would also prevent the executable from running under Win2K and WinXP-SP1.

Fortunately there's an option to fallback to the older runtime libraries:

<PlatformToolset>v90</PlatformToolset>

After it was set - the produced EXE became almost identical to the one built by VC9, including size, import table, sections, safe exception handler table, resources and etc.

So that now it's possible to benefit from some of the new features, without sacrificing the code quality.

Check out these MSDN articles that outline changes in Visual Studio C++ 2010:

This might help you out a bit. Unfortunately it might not be detailed enough (depending how much detail your looking for).

http://blogs.msdn.com/b/vcblog/archive/2009/11/02/visual-c-code-generation-in-visual-studio-2010.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM