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

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

问题描述

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



我们迁移了我们的项目,但是负责人告诉我们,我们必须保留一些基础在我们的生产机器上使用VC9编译的常用DLL一段时间。



这些DLL使用自定义结构,其中一些包含 std :: vector std :: map 等等。现在,我注意到标准容器的尺寸发生了变化:有些变得越来越大,有的越来越小。因此,我们的定制结构的大小也发生了变化。



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



我觉得这个解决方案是可怕的,因为尺寸很重要,结构的布局也是如此。对我而言,增加所有结构的内存占用以解决组织问题似乎是错误的。



为了简化,我的问题是:是否可以同时使用两个在功能原型中使用非C类型时,使用不同的运行时(使用所描述的技巧或任何其他技巧)?对于类似的情况,你有什么好的/不好的经历吗?

解决方案

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



如果要构建可以安全地使用不同编译器版本的DLL,您可以使用以下选项:


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

  2. 暴露 abstract interface 在DLL界面上,就像在这个文章

  3. 使用 COM


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.

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.

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 ?

解决方案

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.

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

  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天全站免登陆