I understand that allocating memory in one dll and then free in another can cause all kinds of problems, especially with respect to CRTs. Similar problems are especially problematic when it comes to exporting STL containers. Previously, we encountered similar problems (when writing custom Adobe plugins associated with our libraries), and we worked on these problems by defining our own dispenser that we use in all our containers, for example:
typedef std::vector < SessionFields, OurAllocator < SessionFields > > VectorSessionFields; typedef std::set < SessionFields, std::less < SessionFields >, OurAllocator < SessionFields > > SetSessionFields;
This works well when passing types to / from our code, however we are faced with the problem that now we need to call a function in the Adobe SDK that returns a populated vector that causes a crash when the region exits.
Obviously, the memory issue is highlighted in the Adobe SDK owned by another heap when it finally freed up in my code. So I think that maybe I could do something smart, somehow redefine or export the dispenser used in their SDK so that I can use it to clean the containers returned from their functions.
I also look at creating a wrapper or some kind of thunking layer in which the STL containers will be safely distributed between my code and the SDK (although this sounds very dirty).
Alternatively, I also consider using GetProcessHeaps to determine the heap used in the SDK, and try to free it from this heap instead of the default heap.
Does anyone have any tips on how we can solve this problem?
c ++ memory-management malloc dll stl
Alan
source share