开发者

Calls to singleton library

I have a singleton class, and I will compile it as a library static(lib) or dynamic(dll).开发者_Go百科

Is it guaranteed that calls to same file in a machine always refer to same and unique instance in both cases?

Edit: What if a process loads two different library and different functions from these libraries want to use instance of singleton class. Now, they are accessing same instance, am I right?

Thanks,


No, different processes will not share a singleton from a common library. Different processes use different memory spaces, so each will instantiate its own singleton.

You'll need to use some sort of shared memory or interprocess-communication to share data between processes.

If a single process loads libraries A and B, and both those libraries use a singleton from library C, then they will be using the same instance.


You don't call files. You load code into your process from the file, the code contains initialisation instructions that construct your singleton. The singleton is thus unique within your process, regardless of what other code within the process uses it. The singleton is not unique from one process to another, even if they use the same shared library.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜