Dynamically load a class from the library and use it after closing the library

TL DR: Is it possible to load a class object from the library at runtime, close the library, and then use the object as a “normal” object (after closing)?

I am trying to implement a plug-in system with some kind of hot-swap feature. Suppose my program expects functions from its plugins doSomething(). My idea would be to scan the file system for any libs in a specific folder, extract functions and then close lib (before using functions!). Thus, the monitor stream can simply track changes in the file system and reset the function pointer in case something has changed, and thus plugins can be "hot".

I believe that the function pointer will become invalid as soon as I close the library (is that so?). Therefore, my idea is to allow the library to return a copy of an object that performs the desired functionality. In this case, I would call lib to create the object before closing it and save a copy of the object in my program. However, since an object can use other objects / functions of the library, I am not sure if this will work, since these objects / functions will not be available, right?

+3
source share
2 answers
  • , , . OS , . , ?

  • - . Proxy, . , , , , . , " " .

  • , 2, concurrency (, , ?).

+4

- , . - , - . , , , (, , ), , - (, ).

, .

+1

All Articles