对于 C++ 插件系统来说什么是安全的?

What#39;s safe for a C++ plug-in system?(对于 C++ 插件系统来说什么是安全的?)
本文介绍了对于 C++ 插件系统来说什么是安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

C++ 中的插件系统很难,因为 ABI 没有正确定义,并且每个编译器(或其版本)都遵循自己的规则.然而,Windows 上的 COM 表明可以创建一个最小的插件系统,允许使用不同编译器的程序员使用简单的界面为宿主应用程序创建插件.

Plug-in systems in C++ are hard because the ABI is not properly defined, and each compiler (or version thereof) follows its own rules. However, COM on Windows shows that it's possible to create a minimal plug-in system that allows programmers with different compilers to create plug-ins for a host application using a simple interface.

让我们务实一点,把在这方面不是很有帮助的 C++ 标准暂时搁置一旁.如果我想为 Windows 和 Mac(以及可选的 Linux)编写一个支持 C++ 插件的应用程序,并且如果我想为插件作者提供相当多的编译器选择(比如不到 2 年的 Visual C++ 版本)、GCC 或 Intel 的 C++ 编译器),我可以指望 C++ 的哪些特性?

Let's be practical, and leave the C++ standard, which is not very helpful in this respect, aside for a minute. If I want to write an app for Windows and Mac (and optionally Linux) that supports C++ plug-ins, and if I want to give plug-in authors a reasonably large choice of compilers (say less than 2 year old versions of Visual C++, GCC or Intel's C++ compiler), what features of C++ could I count on?

当然,我假设插件是为特定平台编写的.

Of course, I assume that plug-ins would be written for a specific platform.

在我的脑海里,这里有一些我能想到的 C++ 特性,我认为答案是:

Off the top of my head, here are some C++ features I can think of, with what I think is the answer:

  • vtable 布局,通过抽象类使用对象?(是)
  • 内置类型、指针?(是)
  • 结构,联合?(是)
  • 例外?(否)
  • extern "C" 函数?(是)
  • stdcall 具有内置参数类型的非外部C"函数?(是)
  • 具有用户定义参数类型的非标准调用非外部C"函数?(否)

如果您能分享在该领域的任何经验,我将不胜感激.如果您知道任何具有 C++ 插件系统的中等成功的应用程序,那也很酷.

I would appreciate any experience you have in that area that you could share. If you know of any moderately successful app that has a C++ plug-in system, that's cool too.

卡尔

推荐答案

Dr Dobb's Journal 有一篇文章 构建您自己的插件框架:第 1 部分 这是关于该主题的非常好的阅读.这是一系列文章的开始,涵盖了 C/C++ 跨平台插件框架的架构、开发和部署.

Dr Dobb's Journal has an article Building Your Own Plugin Framework: Part 1 which is pretty good reading on the subject. It is the start of a series of articles which covers the architecture, development, and deployment of a C/C++ cross-platform plugin framework.

这篇关于对于 C++ 插件系统来说什么是安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why does C++ compilation take so long?(为什么 C++ 编译需要这么长时间?)
Why is my program slow when looping over exactly 8192 elements?(为什么我的程序在循环 8192 个元素时很慢?)
C++ performance challenge: integer to std::string conversion(C++ 性能挑战:整数到 std::string 的转换)
Fast textfile reading in c++(在 C++ 中快速读取文本文件)
Is it better to use std::memcpy() or std::copy() in terms to performance?(就性能而言,使用 std::memcpy() 或 std::copy() 更好吗?)
Does the C++ standard mandate poor performance for iostreams, or am I just dealing with a poor implementation?(C++ 标准是否要求 iostreams 性能不佳,或者我只是在处理一个糟糕的实现?)