Tobias wrote:
can someone clarify if the memory management (memory manager interface) is meant for scoping.
IMHO it's not and I am willing to make it scopable.

I want to pass scoped memory managers to certain helper functions (xercesc/util/...) and think that this only works in non-exceptional or catch-all circumstances. If those functions (e.g. XMLString::parseInt) throw an exception the scoped memory manager
is passed via ThrowXMLwithMemMgrXXX to the exception during construction.
The exception allocates memory for its internal buffers (message/source file) from that memory manager. If the exception is not caught before the scoped memory manager goes out-of-scope, dereferencing/deallocating the memory during reporting/destruction yields undefined behaviour.
Yes, I ran into this when I was using Xerces-C's pluggable memory management as well.


IMHO exceptions should allocate memory for their interal buffers from a static memory manager: Exceptions should query the memory manager interface via a new virtual function for some kind of "global" memory manager instance. In the memory manager default implementation this function just returns the this-pointer to ensure backward compatibility. Scoped memory managers now have the change to override it and delegate requests to a static memory manager, e.g. XMLPlatformUtils::fgMemoryManager.
I was thinking of something similar, but decided that exceptions should _always_ use the static MemoryManager instance. Your idea will certainly work, but can you think of a real use case where this would be valuable?


I think the best approach to make the memory management scopeable is
1. to add a method "virtual MemoryManager* getGlobalMemoryManager()" to the MemoryManager interface that returns the this-pointer 2. to add a call to getGlobalMemoryManager in the XMLException constructor for the memory manager instance passed in as a parameter and save and use the "global" memory manager instance instead of the passed memory manager instance.
It would certainly work, although I wonder if it the function should really be called "getExceptionMemoryManager," since the global MemoryManager instance is always available through the static pointer. It could be confusing if an implementation returned something other than the global instance, and a user thought they were really getting the global one.


does anyone has a different suggestion or can confirm this approach,
so that I can fill out a feature request and provide the patches??
I'm willing to review and commit the patch, if others agree it would be useful.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to