I would not recommend tranforming to a XalanDOMString then casting every character to a narrow character. It will work, but you're still paying a fairly hefty price for dynamic memory allocation, plus you'll end up using twice as much memory as you really need. If you still decide to do this, you might want to call XalanDOMString::reserve() and reserve a fairly large amount of memory up-front, to avoid repeated reallocations.

If you find the performance of ostringstream is not good, you can try using ostrstream with your own buffer, which will save the cost of dynamic memory allocations. The disadvantage is that you'll need to know the maximum size of the data ahead of time, or figure out a way to recover if the data overruns your buffer.

Another is to use the callback mechanism to write the data to your own buffer. See the XalanTransformerCallback sample for more information.

Dave

Holger Floerke <[EMAIL PROTECTED]>




          Holger Floerke <[EMAIL PROTECTED]>

          07/22/2002 03:57 AM
          Please respond to xalan-dev



To: [EMAIL PROTECTED]
cc: (bcc: David N Bertoni/Cambridge/IBM)
Subject: Xalan-C: Two Ways to Transform into ByteStream

I use XalanTransformer for transformation. My stylesheet includes
<xsl:output method="html" encoding="iso-8859-1">. The result is about 1MB HTML.

If I use "ostringstream" as the ResultTarget

ostringstream oResult;
XSLTResultTarget oResultTarget(oResult);
...
m_oTransformer.transform(...)
...

the rendering-time is two times larger than using "XalanDOMString"

XalanDOMString oResult;
DOMStringPrintWriter oDOMPrint(oResult);

XSLTResultTarget oResultTarget(&oDOMPrint);
...
m_oTransformer.transform(...)
...

I need a "single"-byte stream for output. Therefore I can't use
XalanDOMString holding UTF-16 :^(

But I told the stylesheet to render "iso-8859-1". Can I go on with

XalanDOMString::CharVectorType oLocal;
oLocal.resize(oResult.size());
for (XalanDOMString::size_type nI = 0; nI < oResult.size(); nI++)
{
oLocal[nI] = (char) oResult[nI];
};
to convert XalanDOMString into single-byte array? What happens if there are
characters above 255? Does the processor convert them to "&#...;"? If I
have to use ostringstring: Can I preallocate the buffer?

TIA

HolgeR

--
holger floerke d o c t r o n i c
email [EMAIL PROTECTED] information publishing + retrieval
phone +49 2222 9292 90
http://www.doctronic.de



GIF image

Reply via email to