Главная страница | назад





Article #15458: Turning off RTTI in one DLL and not the other

 Question and Answer Database

FAQ458C.txt   Turning off RTTI in one DLL and not the other
Category   :C/C++ Language Issues
Platform    :All
Product    :BC++  5.x

Question:


 Is possible to turn off RTTI in one DLL and not the other?

Answer:
You probably shouldn't do this --- as it undermines the point to a certain
extent, but : recode so that your class is constructed within DLL, then
create an instance of that class by creating a "class factory" --- eg.,  a
static member function in your DLL1 that will provide an instance of class A.

Then you can be certain that the class was manufactured using the same memory
allocation and compile options as the code using the class is expecting.

e.g. 

  class A {
   public:
  
     A(int);
     
     A* Create(int i) {
       return new A(i);
     }
     
     void Destroy(A* a) { delete a; }
  };

As a general rule, if you are using classes across DLLs you should use the
same options in all modules and use dynamic link libraries. The only 
exception to this would be that you have deliberately coded so that memory
allocation and data access does not cross DLL boundaries.

The importance of memory allocation is that most (all?) C++ implementations
call new from the calling function and delete from within the destructor. With static RTLs this leads to two "different" RTLs doing memory allocation
and there is no guarentee that they will access the same memory pool. Back to
RTTI, effectively you have a non-RTTI memory allocation from your second DLL
as that is where the new is executed.

7/2/98 10:32:32 AM
 

Last Modified: 01-SEP-99