是混合运行时一个可行的解决方案? [英] Is mixing runtimes a viable solution?

查看:186
本文介绍了是混合运行时一个可行的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我公司,我们最近从VC9切换到VC10。

At my company, we recently switched from VC9 to VC10.

我们迁移了我们的项目,但是负责人告诉我们,

We migrated our projects but then, the person in charge told us we would have to keep some base common DLLs compiled with VC9 on our production machines for some time.

这些DLL使用自定义结构,其中一些包含 std :: vector std :: map 等。现在,我注意到标准集装箱的尺寸改变了:一些更大,一些更小。因此,我们的自定义结构的大小也改变了。

These DLLs make use of custom structures, some of which contain std::vector, std::map and so on. Now, it has come to my attention that the size of standard containers changed: some got bigger, some got smaller. As a result, the size of our custom structures changed as well.

为了解决由大小变化引起的问题,我的一个同事想到人为地增加大小我们的结构使得可能补偿未来的成员大小变化,使得结构保持相同的大小,无论我们使用什么运行时,防止函数调用上的堆栈损坏。

To solve the issues caused by the size change, a colleague of mine thought of artificially increasing the size of our structures to make it possible to compensate for future members size changes so that the structures keep the same size, whatever runtime we use, preventing stack corruption on function calls.

,我觉得这个解决方案是可怕的,因为虽然大小重要,结构的布局也是如此。对我来说,增加所有结构的内存占用来解决组织问题似乎是错误的。

Personally, I feel that this "solution" is horrible because while the size matters, so does the layout of the structures. To me, increasing the memory footprint of all structures to fix organizational issues seems really wrong.

为了简化,我的问题是:甚至可以同时使用两个不同的运行时(使用描述的技巧或任何其他技巧),而在函数原型中使用非C类型?

To make it short, my question is: is it even possible to use simultaneously two different runtimes (using the described trick or any other trick) while using non-C types in the function prototypes ? Do you have any good/bad experience regarding a similar situation ?

推荐答案

STL从来没有保证不同主要版本之间的二进制兼容性。所以,如果你在接口有DLL的STL类,你应该使用相同的编译器和相同的风格的CRT客户端的DLL和DLL本身。

The STL never has guaranteed binary compatibility between different major versions. So, if you have DLL's with STL classes at the interface, you should use the same compiler and the same flavor of the CRT for the client of the DLL and the DLL itself.

如果你想构建DLL可以安全地使用不同的编译器版本,你有一些选项,如:

If you want to build DLL's that can be safely used with different compiler versions, you have some options, like:


  1. strong> pure C 接口(DLL可以用C ++编写,但接口必须是纯C,而C ++异常不能跨越DLL边界)。

  2. strong>抽象接口,如本文章中所述。

  3. 使用 COM

  1. Expose a pure C interface (the DLL can be written in C++, but the interface must be pure C, and C++ exceptions can't cross DLL boundaries).
  2. Expose abstract interfaces at the DLL interface, like explained in this article.
  3. Use COM.

这篇关于是混合运行时一个可行的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆