share memory between dll in the same process
I have a class named CMemCfg which is a singleton, the CMemCfg class has a lot of data members which storage configuration data . If I put CMemCfg in server.exe, then other dlls should uesd callback function to visit function(get data from data members) in CMemCfg . So I want to put the CMemCfg class(also a singleton) in a dll, but that will cause another problem, every function of CMemCfg should have an export function which lead to duplication o开发者_JAVA技巧f code. Should I just export CMemCfg(singleton) class? Is there another solution to share memory between dll in the same process? Any help would be greatly appreciated.
You may consider initializing other dlls with instance of CMemCfg. No callbacks, no duplicating exports, the only change is modified (added) initialization function.
I think you should stick with exporting the class from the DLL. To export a class from a dll you only need to declare that you are exporting the class, and not each member variable. You can use dll main to create the singleton instance, and export a function along the lines of "GetSingletonObject()
" to allow clients to use your object.
You could use shared memory section to share memory, but I think this will be more work than just exporting the singleton.
精彩评论