Best way for dlls to share data?

Started by
2 comments, last by KevinLee 18 years, 4 months ago
I'm wondering what a fast an reliable way for 2 independant dlls to share data. I've read a bit about pipes and memory mapped files but wanted to get some opinions. It should preferably be usable on windows and linux, though I don't might doing some specific coding for each if necessary. Essentially what I'm wanting to do is give dllA access to a potentially large block of contiguous memory that is managed by dllB. dllB is loaded and in-use by a game. One way would be to allow dllA to LoadLibrary and GetProcAddress of dllB and use some exported functions to access the memory. This may be the easiest to go with, but I'd still like opinions either way. Thanks in advance.
Advertisement
As for Windows, I'd definitely go with memory mapped files to create a shared memory pool that can be used by the two dlls. If I understand your second solution, you're simply mapping the two dlls into the address space of the application. This is ok as long the dlls don't need cross process communication.
To clarify my last resonse: you only need a shared memory pool (via memory mapped files) if you need the dlls to communicate between processes
(i.e. dllA is loaded by app A and the dllB is loaded by app B). If the dlls are loaded by the same app, then they already exist within the virtual address space of the application so nothing special needs to be done. To be on the safe side though, you should make sure that the dlls and app are using the same version of the C runtime library.

I recommened going to MSDN and doing a search for dlls and memory mapped files to get more details.
It seams that both of this dlls are loaded into a same process. So, you can access whatever you want in one process memory space. Do you mean cross-process communication?

This topic is closed to new replies.

Advertisement