简体   繁体   中英

How can I have one singleton per dylib?

I'm trying to make a VST plugin (a dynamic library for audio software), with a singleton in it (using a static C++ member). The problem is, when I try to load more than one instance of the plugin (ie 2 copies of the dylib) the static members get shared, ie the 2 instances of the dylib share the same dylib. Is there a mechanism that lets you disable sharing of static variables across the dylib boundary? eg so each instance of the same dylib has its own singletons?

All dynamic libraries I know of are a single binary, a single instance of which is loaded into memory and used by multiple processes. If that single instance has a singleton in it, then all processes that use that shared library will see the same singleton. What you actually want is a dynamic set of these objects. Create one when a process loads the library, and destroy the corresponding one when a princess unloads the library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM