You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Alex Brown <al...@griffinbrown.co.uk> on 2002/01/24 16:28:31 UTC

How to delete memory allocated by XMLString::transcode

The docs say:

"NOTE: The returned buffer is dynamically allocated and is the
responsibility of the caller to delete it when not longer needed."

But what function should be used for deleting the buffer? There's no
guarantee (is there?) that the delete[] I might be using properly
corresponds to the new[] that Xerces has used. Shouldn't there be a static
method XMLString::freeBuffer to do this safely?

- Alex.


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: How to delete memory allocated by XMLString::transcode

Posted by Joachim Achtzehnter <jo...@netacquire.com>.
Alex Brown wrote:
>
> "NOTE: The returned buffer is dynamically allocated and is the
> responsibility of the caller to delete it when not longer needed."
>
> But what function should be used for deleting the buffer? There's no
> guarantee (is there?) that the delete[] I might be using properly
> corresponds to the new[] that Xerces has used.

Xerces uses an ordinary call to C++ new, hence your call to delete[] is
just fine. However, if you are on a Microsoft platform you must be very
careful to ensure that the system actually behaves as the C++ standard
specifies. Most importantly, the code that calls delete[] must use the
same C runtime DLL as the Xerces DLL. Usually, this requires linking with
xerces-c_1D.lib if your settings include "Debug Multithreaded DLL" (/MDd),
and link with xerces-c_1.lib (without the 'D') if your settings are
"Multithreaded DLL" (/MD).

> Shouldn't there be a static method XMLString::freeBuffer to do this
> safely?

This would have prevented some problems on Microsoft platforms for
programs that use multiple C runtimes, but using multiple C runtimes is
not a good idea anyway (it breaks standard C/C++ semantics, wastes
resources, and can cause subtle runtime problems).

Joachim

-- 
work:     joachima@netacquire.com   (http://www.netacquire.com)
private:  joachim@kraut.ca          (http://www.kraut.ca)


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org