Ironically enough, the Adobe Source Libraries has a adobe::capture_allocator class that was written specifically with this kind of DLL safety in mind. The way it works is to capture the local new and delete at this point it is instantiated, and to carry them both around for the lifetime of the object. (See adobe::new_delete_t for details on how it does this, especially the implementation here ) Deallocations take place with the captured delete routine, guaranteeing that no matter where you are you are deleting with the proper delete You can see capture_allocator used throughout the version_1 types in the Adobe Source Libraries, such as adobe::any_regular_t and adobe::copy_on_write capture_allocator should be compatible with all STL container types as well Update: capture_allocator is not standard-compliant because it retains state.
This should not be a big hindrance to its usability, but it does mean its use is not guaranteed to work with standard-compliant containers.
Ironically enough, the Adobe Source Libraries has a adobe::capture_allocator class that was written specifically with this kind of DLL safety in mind. The way it works is to capture the local new and delete at this point it is instantiated, and to carry them both around for the lifetime of the object. (See adobe::new_delete_t for details on how it does this, especially the implementation here.) Deallocations take place with the captured delete routine, guaranteeing that no matter where you are you are deleting with the proper delete.
You can see capture_allocator used throughout the version_1 types in the Adobe Source Libraries, such as adobe::any_regular_t and adobe::copy_on_write. Capture_allocator should be compatible with all STL container types as well. Update: capture_allocator is not standard-compliant because it retains state.
This should not be a big hindrance to its usability, but it does mean its use is not guaranteed to work with standard-compliant containers.
This is a very common technique, I've seen it in C too where one library requires its users to supply a allocation/de-allocation callback via some kind of library init() point. – Justin Aug 27 '09 at 23:29.
At the moment we're working on a dll which exposes C++ functionality via a C interface (for the sake of C# being capable of using the said dll). For instance : the dll has a struct myStruct_s the interface exposes the following functions : interface. H #ifndef INTERFACE_TYPES_H # error Please include interace_types.
H #endif myStruct_s * CreateTheStruct() { return new myStruct_s(); } void DestroyTheStruct(myStruct_s * the_struct) { delete the_struct; } void DoSomethingToTheStruct(myStruct_s * the_struct); interface_types. H #define INTERFACE_TYPES_H struct myStruct_s; // fwd declaration #endif interface. Cpp #if defined(__CPPPLUS) || defined(__cplusplus) || defined (__CPLUSPLUS) #include // handle the .
H's functions here #endif comeOutsideCppFile. Cpp #include "interface_types. H" #include "interface.
H" void main() { myStuct_s * x = CreateTheStruct; DoSomethingToTheStruct(x); DestroyTheStruct(x); } The above is a rough outline of how our stuff works, basically : Whatever the dll exposes needs to be : Created, Handled, Destroyed dll-side This code is not 100% accurate! Also, please keep in mind that if you're using a pure C++ dll, you probably need the same compiler with the same settings as the one used to build the dll.
1 @Maciek: interface. H should contain NON-inline functions. By making the functions inline, they will be compiled in the compilation unit of comeOutsideCppFile.
Cpp, which ruins the concept. – shojtsy Nov 28 '09 at 6:33.
You might try looking to see if there are any formal C++ rules for what happens when an exception is thrown in one DLL and caught in another and then goes out of scope -- it seems very similar. For exceptions, I think you are required to provide a copy constructor with a special signature, though I'm unsure now exactly what it is.
Ironically enough, the Adobe Source Libraries has a adobe::capture_allocator class that was written specifically with this kind of DLL safety in mind. The way it works is to capture the local new and delete at this point it is instantiated, and to carry them both around for the lifetime of the object. (See adobe::new_delete_t for details on how it does this, especially the implementation here .) Deallocations take place with the captured delete routine, guaranteeing that no matter where you are you are deleting with the proper delete .
At the moment we're working on a dll which exposes C++ functionality via a C interface (for the sake of C# being capable of using the said dll).
Your "solution" just adds another memory manager to the mix, so it only adds more possibilities for allocation and deallocation being done by different memory managers. Edit: If you can enforce that all memory allocation and deallocation uses your memory manager which is confined within a single DLL, it will probably work just fine. However, as Hans Passant noted in the comments, if you can enforce that you can most likely also enforce that all components use the same CRT version.
DLLs are only associated with this problem because most memory allocation happens via memory managers provided by the C or C++ run time, and those commonly differ (even more so than the rest of the run time libraries) depending on how the DLL was compiled. You can successfully allocate and deallocate across DLL boundaries if you're careful, and you can get similar problems within a single DLL.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.