c ++,dll的多个实例,单例 [英] c++, multiple instances of a dll, singleton

查看:556
本文介绍了c ++,dll的多个实例,单例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DLL,其中定义了一个单例。

I have got a DLL in which a singleton is defined.

我有一个应用程序可以加载这个DLL的多个实例。

I have got an app which can load multiple instances of this DLL.

DLL需要每个DLL实例有一个singleton实例,否则会崩溃。

The DLL needs a singleton instance per DLL instance, otherwise it will crash.

我观察到, DLL实例。为什么?

I observed that there was only one singleton instance for multiple DLL instances. Why? How can I resolved it (if possible, without refactoring the singleton into something else)?

感谢您的帮助。

推荐答案

如果你没有dll的源,那么你必须加载它在不同的进程,每个进程一个单例。这些可能是简单的子进程到你的主进程,只处理dll通信部分。

And if you don't have the sources to the dll, then you must load it in different processes, one "singleton" per process. These could be simple child-processes to your main process that just handle the dll communication part.

当然,你必须在你的主进程和你的子进程之间有一些通信方案,这将取决于你使用dll的多少。是只是几个电话与大量的数据?或者有很多不同的调用与运行不同?

Then of course, you must come with some communication scheme between your main process and your child processes, which will depend on how much you are using the dll. Is it just a couple of calls with a lot of data? Or a lot of different calls that differ from run to run?

一般来说,如果你使用dll来做一些简单的调用,可能更容易重构你的自己的代码。

Generally if you are using the dll to make more than a couple of simple calls it's probably easier to refactor your own code.

这篇关于c ++,dll的多个实例,单例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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