At 09:56 AM 10/06/2002 +0100, Gert van Spijker wrote: >Here is a code fragment, that works well on my system, from my MSVC code >that converts a nodes value to a MFC CString: > >char* pValue = XMLString::transcode( pNode->getNodeValue() ); >CString Value = pValue; >delete pValue;
This code fragment isn't correct, since it should be using delete[] to free the memory. If it works, you're lucky and relying on a "quirk" of the platform you're using. ;) On a somewhat semi-related note, this issue seems to crop up all the time. Has any consideration been given to an STL-allocator-style API for allocating and freeing memory returned by the transcode() family? I believe the kind of problems that we're seeing were part of the motivation for the STL allocator<> design. Other ideas for mitigating these problems are introducing a proxy-type for the return result, so that the function signatures do not confuse as they currently appear to. A proxy-type would also have the advantage that it could, by default, release the resource when destroyed (auto_ptr<> style). For what it's worth, we use an in-house equivalent to std::auto_ptr<> that uses delete[] instead of delete during destruction. That's been suitable for all our purposes so far, mainly since the results of transcode() are usually short-lived; the results are usually sent to I/O or shoved into a std::string. - Andrew --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
