Jump to content
  • Advertisement
Sign in to follow this  
MrRage

DLL shared memory

This topic is 4853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to pass a pointers rather than a copy of data or C++ objects between DLL’s and the program that linked to them? I’m sure it is but I just wanted to know that before I started working with them, so I know what to expect.

Share this post


Link to post
Share on other sites
Advertisement
Yes. You only can't pass pointers if you're passing to another EXE, since it has a different address space. When a DLL is loaded, it shared the same address space as the EXE.

EDIT: Be careful about passing STL containers between a DLL and an EXE. You can't allocate memory in the EXE (with new, malloc, etc) and free it in the DLL (with delete, free, etc) or vice versa. If you must pass STL objects between the EXE and DLL, make sure you only pass by const reference, and never return by value.

Share this post


Link to post
Share on other sites
Ah ok, so the DLL can't directly manage memory on the EXE side of the application, or the EXE manage memmory for the DLL.

Share this post


Link to post
Share on other sites
Quote:
Original post by MrRage
Ah ok, so the DLL can't directly manage memory on the EXE side of the application, or the EXE manage memmory for the DLL.
Exactly. You can still change memory in the EXE from the DLL (via a pointer), but you can't reallocate memory.
The reason for this is that under Windows, the DLL and the EXE have seperate heaps. If you really need to allocate memory in the DLL and free it in the EXE, you can link both the EXE and DLL to the DLL version of the CRT. Then new and delete are called from within the context of the CRT DLL, and everyone (well, Windows) is happy [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!