Boost logo

Boost Users :

From: Metasebia Moges (mtsbmoges_at_[hidden])
Date: 2007-04-21 04:49:32


Dear Bronek Kozicki,

>because it really is bad idea. I will explain why: C++ runtime needs
>access to the heap in order to be able to create objects (like strings).
>On Windows each process owns multiple heaps and the runtime holds handle
>to one. If you use static runtime, this handle is linked into executable
>(it's a static variable). On Windows you have two kinds of executables:
>DLL and EXE. Each copy of static C++ runtime that is statically linked
>into an executable will have own heap handle, thus heaps (of EXE and all
>DLLs linked with static runtime, running inside the process) will be
>separate. Now imagine what happens if function inside a DLL creates a
>string (be it 'std::string("foo bar")' or simply 'new char[20]') and
>returns it to EXE that called it - string would be created in the
>context of C++ runtime statically linked with the DLL (one heap) and
>then passed (and some time later destroyed) in the context of another
>C++ runtime, the one statically linked into the EXE (other heap). The
>trouble is that you cannot allocate memory on one heap and then free it
>on another, because they know nothing of one another - the attempt will
>likely simply corrupt the heap of the other runtime (thus crashing your
>process some time later). This is why whenever you want to use DLL and
>EXE and pass C++ objects of or pointers between them, it is crucial that
>they all (DLLs and EXE) use one copy of the C++ runtime - that is
>dynamically linked one (option /MD for release build and /MDd for debug).

What a nice lecture! Thank you very much. That helped me fix the problem. One additional thing worth mentioning is that I had to copy the boost_regex_vc71_mt_gd_1_33_1.dll into my the directory where I placed all my executables (dlls and exe). I wonder if that was mentioned somewhere in the documentation! Moreover, eventhough the boost.regex code is only in one of the dlls (isolated), I had to include the macro BOOST_REGEX_DYN_LINK (but, Dr. Maddock once informed me that this is not necessary). Just wondering. Thank you again!

Best regards,

mmoges

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net