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 Curt Arnold <ca...@houston.rr.com> on 2001/01/20 06:27:06 UTC
transcode patch for consideration
I've put a zip file (http://home.houston.rr.com/curta/xalloc.zip)
with modified versions of a handful of files from the Xerces CVS
that I think provides a fairly nice solution to the debug RTL
problem that we have been discussing recently plus has some very
nice behavior for use with STL and other strings.
There are a couple of aspects to the modifications:
1. A DOMString::free() and XMLString::free() are added that
indirectly call delete[] of the C++ RTL used by Xerces. Using
these instead of an inline delete[] should eliminate the debug
mode crashes.
2. Existing code that uses delete[] inline has unchanged
behavior, crashes when Xerces and the calling app have different
RTL's and works if they are the same.
3. Parallel versions of char* transform() and XMLCh* transform()
are added that take an XMLTransAllocator* as an argument that is
used in the buffer allocation. When these method are used, the
free() method of the same allocator should be used to release the
returned buffer.
4. Custom implementations of XMLTransAllocator can be used to
optimize the performance of transcoding for specific uses. For
example, if you are transcoding a large number of short strings
sequentially and assigning them to STL basic_strings's, you could
write an allocator where free() is a NOP, something along the
lines of (grossly simplified)
class MyAllocator : public XMLTransAllocator {
public:
char* alloc(unsigned int size) { return mBuf; }
XMLCh* alloc(unsigned int size) { return mXMLChBuf; }
void free(char*) {}
void free(XMLCh*) {}
private:
char mBuf[1024];
XMLCh mXMLChBuf[1024];
};
void MyClass::DoSomething() {
MyAllocator alloc;
for(int i = 0; i < 100000; i++) {
DOMString attr = ...
str::basic_string<wchar_t> a(attr.transcode(&alloc));
}
}
All the available platform transcoders seemed to be readily
adaptable to passing in an arbitrary transcode with the possible
exception of the Mac which use ArrayJanitors and other fun stuff.
If that is needs to be maintained, then the implementation of
XMLTransAllocator::getDefaultAllocator() just needs to be moved
into the platform specific code.
Re: transcode patch for consideration
Posted by Bill Schindler <de...@bitranch.com>.
Why not just change DOMString::transcode to take an optional length and
char*? If the caller passes in a length and buffer, transcode uses that
instead of allocating one. The underlying transcoders all work on a
passed-in buffer, so the change would be local to DOMString::transcode. If
the parameters are defaulted, then existing code doesn't break:
char * DOMString::transcode(unsigned int length = 0, char * buffer = 0);
If buffer is NULL, we'd allocate as we always have. If it's allocated, we
pass it along to the transcoder.
--Bill