Jump to content
  • Advertisement
Sign in to follow this  

std::vector and heap allocation on DLLs

This topic is 4522 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

Hi, I am making an interface for a DLL that looks like this: class __DllExport MyInterface { std::vector <int> MyArray; . . . } I have a class like this defined both in the DLL and in the main program, with the usual __DllImport & __DllExport interfaces. In the main program, I create multiple objects of type "MyInterface"... My question is... the memory allocated by MyArray vector, is stored in the DLL memory heap, or in the EXE memory heap? Is this mechanism safe? or it can cause some memory problems, like trying to allocate/deallocate memory in the wrong memory heap? Vic

Share this post


Link to post
Share on other sites
Advertisement
Unless the vector is exported then this construct is not safe. In general classes defined in DLLs should have as few implementation details visible as possible. Consider creating an abstract base class and a factory function in your DLL that produces instances of that class.

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!