I have an application that is built with Visual Studio 2012, and thus it depends on MSVCP110.DLL and MSVCR110.DLL. I'm using another DLL file, which seems to have been built with Visual Studio 2010 and depends on MSVCP100.DLL and MSVCR100.DLL. Yet another DLL I have was build with Visual Studio 2008 and depends on MSVCR90.DLL.

Is this a bad thing? A really bad thing? Should I be worried? The reason I ask is that the runtime heap allocator is complaining about heap corruption. Could this be related to the mixed runtime versions?

  • 1
    Yes. It is a very bad thing to try to use more than 1 visual studio runtime in your application at a time. The main reason is each CRT has its own independent heap (no communication between heaps). And this means you can not allocate memory in 1 heap and free it in a second. This will lead to heap corruption and will cause random crashes because the corruption may not cause a crash on the next allocation or deallocation. – drescherjm Nov 13 '13 at 3:32
  • BTW Visual Studio 2010 runtime will be have 100 in the file name. – drescherjm Nov 13 '13 at 3:46
  • @drescherjm - fixed the filenames. Copy and paste error. – Ted Middleton Nov 13 '13 at 21:46

It's not safe to mix and match Visual Studio runtimes from different compiler versions mainly because each runtime will create its own independent heap. Since the heaps will be totally independent you can not allocate memory using 1 heap and free it in a different heap. Doing so will corrupt your heaps. The corruption does not usually cause an immediate crash since the corrupt part of the heap may not be accessed on the next few allocations or deallocations so it can be very hard to debug.

For the case of a single dll having a different heap than the application it is possible to work around the problem in a very limited way. You would have to isolate the dll such that all allocations and deallocations of dll happens only inside of the dll. And also isolation would have to go the other way as well. The dll will not be able to safely free memory from the applicaton without isolation.

More info on heap corruption caused by mixing CRT versions can be found here: http://siomsystems.com/mixing-visual-studio-versions/

  • 1
    <sigh> That's more or less what I thought. It would be difficult to isolate allocations across these different modules, so I'm going to have to do the hard work of rebuilding them with vs2012. Thanks! – Ted Middleton Nov 13 '13 at 5:25

Your Answer

