Original Post
Hi all, I'm embarking on a life-long C++ journey (I guess) to create an architecture to simulate old-style pen & paper RPGS: The Multiple Role Playing Simulator As I need maximum modularity, I'm starting off with Plugins right from the start. I've read Petzold's brief chapter in "Programming Windows" and what Noel Llopis has to say in "C++ for Game Programmers". I've also read the following resources, but still have a few questions: - GameDev Forum: free c++ plugin system - Modular Programming with DLLs - Building a Better Plugin Architecture (C++) - Dynamic Plug-Ins for C++ - Building Your Own Plugin Framework Despite all the information found there, I still have some very basic, perhaps "newbie" type of questions: 1.) According to Petzold, Windows DLLs reside in some kind of common memory (like a part of Windows itself) which is not part of an application program's memory and which multiple applications can access. At the same time any data maintained by a DLL is different for each process:
Quote:Now my question: Suppose I create a Plugin-system with an abstract base class (interface) for Game Objects residing in the main application and many derived subclasses which create the actual Game Objects. I put the derived Game Object subclasses into plugins (DLLs). Then I add to each plugin a factory function or a factory object which is "exported" to the main application and which, when called by the main application, creates the actual Game Object which is also in the plugin (but not exported "publicly"). Where is the Game Object actually created then? Is it created in the main program's memory, the heap? Or is it created in the plugin's process-specific memory? If the latter, is it a problem to create thousands of objects there (memory or speed constraints)? If we pass the created Game Object to the main program as a return-argument (NOT as a pointer!) of the factory function which created it, it's freed from the process-specific memory of the DLL as soon as the factory function terminates, right? Then the Game Object would be re-created in the memory of the main program (as passing by argument makes a copy), probably on the heap, right? If so, how would the main program know how much memory to reserve there for the Game Object if all it has is the implementation of the abstract base class (interface) of the Game Object, but not the implementation of the actual Game Object which it is passed? 2. Studying different sources about plugins I found that Windows seems to support C++ plugins, that is, one can directly put a class into a plugin without a problem. UNIX does not. In UNIX you MUST create a C++ class object in a plugin with a C-style function, right? The article above "Building a Better Plugin Architecture" suggest, instead of exporting a function from a plugin to create an object implemented in a plugin (and perhaps one to destroy it), it would be better to create a (distributed / ABC) factory and one derived factory subclass for each kind of object in a plugin. Then the main program can call this factory which creates and destroys the objects implemented in the same plugin. To create a platform-independent plugin system this means every plugin needs to contain the following parts, right? - The implementation of the derived object class which the plugin should add to the main application. - The implementation of the derived factory class which produces and destroys the above mentioned object. - Because UNIX cannot access C++ objects in plugins directly, we also need C-style function(s) which create and destroy the (singleton) factory object above. These are exported to the main program. Did I get all this right? To build a good plugin architecture as described in "Building a Better Plugin Architecture", every plugin needs an implementation of the object it wants to add to the main program, an implementation of the factory to create it AND C-style Create() - and Destroy() functions which create and destroy the factory object? Sorry if I'm not quite clear about all this. Any help is appreciated! :) Greetings, Mark
Multiple processes can share the same code in a dynamic-link library. However, the data maintained by a DLL is different for each process. Each process has its own address space for any data the DLL uses.