Archived

This topic is now archived and is closed to further replies.

STL warning... weird

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

warning C4251: ''Console::Talksole'' : class ''std::deque<_Ty>'' needs to have dll-interface to be used by clients of class ''Console'' with [ _Ty=std::string ] it''s in the class Console like this: deque Talksole;

Share this post


Link to post
Share on other sites
Due to the way the DLL memory model has be designed, passing STL objects across the application/DLL boundary is ... extremely difficult.

The basic problem is that memory allocated by the DLL must also be deallocated by the DLL (essentially, each DLL keeps its own heap). Given how STL code is inlined, your application will generate its own code to manipulate STL containers.

Which will blow up if it tries to manipulate an object that lives in the DLL.


At least that''s my take on the warning. I''m no Windows expert.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
I''m adopting this as my personal crusade since it comes up so often. Memory allocated in one DLL can be safely deallocated ANYWHERE provided that each DLL and EXE is linked to the shared (read: DLL) version of the RTL. AFAIK, Visual Studio links by default to the static RTL. In that case, each DLL/EXE will get its own heap and that''s what causes "Bad Block" errors when you try to delete a pointer allocated in another DLL. Linking to the DLL version of the RTL will solve this problem. No memory managers or custom allocators are neccessary.

Matt

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi!
Just found your post on the forums about needing to change to the dynamic RTL in order to solve heap problems with STL... how could I go about changing it in Visual C++ 7?

Regards,
Tristan Jones

Share this post


Link to post
Share on other sites