You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Mike Ellery <mi...@s2technologies.com> on 2006/11/03 19:49:51 UTC

XalanTransformer::initialize();

The docs for XalanTransformer::initialize say --

  void XalanTransformer::initialize (  	MemoryManagerType & theManager = 
XalanMemMgrs::getDefaultXercesMemMgr() ) [static]
   	
Initialize Xalan.

Should be called only once per process before creating any instances of 
XalanTransformer. This call is not thread-safe, so you must serialize 
any calls to it, and you must track the initialization state, so you do 
not call it more than once.

------

My application is a server, and it only intermittently needs to call the 
xerces/xalan stuff to serialize current state.  I'd prefer to initialize 
these libraries only when I need them and then release them when I'm 
done (thus getting back any memory that they might be holding on to). 
So, I tried just doing the initialization and termination before and 
after my serialization:

//initialization:
XMLPlatformUtils::Initialize();
XalanTransformer::initialize();

//DO SERIALIZATION WORK

//termination
XalanTransformer::terminate();
XMLPlatformUtils::Terminate();
XalanTransformer::ICUCleanUp();

This violates the docs for initialize, which will be called here each 
time I try to serialize, but my application does not crash with my basic 
tests.

Does anyone have experience doing this?  In general, why can't 
initialize/terminate be called multiple times (like 
XMLPlatformUtils::Initialize can)?

Advice appreciated.

-Mike Ellery


Re: XalanTransformer::initialize();

Posted by David Bertoni <db...@apache.org>.
Mike Ellery wrote:
> 
> 
> David Bertoni wrote:
> 
>>
>> However, you should be very careful about calling 
>> XalanTransformer::ICUCleanup(), because it can cause problems.  Please 
>> read the documentation about static cleanup of the ICU, which is 
>> documented here:
>>
>> http://icu.sourceforge.net/apiref/icu4c/uclean_8h.html#93f27d0ddc7c196a1da864763f2d8920 
>>
>>
>> Xalan-C does not take care of calling u_init() for you -- you must do 
>> it yourself.
>>
> 
> 
> Thanks for the advice.  I actually have the call to ICUCleanup only 
> because it was in one of the examples I looked at.  I probably don't 
> need it (I don't use anything from ICU in my code), but how would I tell 
> for sure whether or not I need this?  Does it depend on my code or does 
> it depend on how Xalan was built?

If Xalan was built with ICU support, and you are worried about releasing 
any memory the ICU has cached, then you'll need it.  If Xalan was built 
without ICU support, then it's a no op.

Dave

Re: XalanTransformer::initialize();

Posted by Mike Ellery <mi...@s2technologies.com>.

David Bertoni wrote:

> 
> However, you should be very careful about calling 
> XalanTransformer::ICUCleanup(), because it can cause problems.  Please 
> read the documentation about static cleanup of the ICU, which is 
> documented here:
> 
> http://icu.sourceforge.net/apiref/icu4c/uclean_8h.html#93f27d0ddc7c196a1da864763f2d8920 
> 
> 
> Xalan-C does not take care of calling u_init() for you -- you must do it 
> yourself.
> 


Thanks for the advice.  I actually have the call to ICUCleanup only 
because it was in one of the examples I looked at.  I probably don't 
need it (I don't use anything from ICU in my code), but how would I tell 
for sure whether or not I need this?  Does it depend on my code or does 
it depend on how Xalan was built?

Thanks,
Mike

Re: XalanTransformer::initialize();

Posted by David Bertoni <db...@apache.org>.
Mike Ellery wrote:
> The docs for XalanTransformer::initialize say --
> 
>  void XalanTransformer::initialize (      MemoryManagerType & theManager 
> = XalanMemMgrs::getDefaultXercesMemMgr() ) [static]
>      
> Initialize Xalan.
> 
> Should be called only once per process before creating any instances of 
> XalanTransformer. This call is not thread-safe, so you must serialize 
> any calls to it, and you must track the initialization state, so you do 
> not call it more than once.
> 
> ------
> 
> My application is a server, and it only intermittently needs to call the 
> xerces/xalan stuff to serialize current state.  I'd prefer to initialize 
> these libraries only when I need them and then release them when I'm 
> done (thus getting back any memory that they might be holding on to). 
> So, I tried just doing the initialization and termination before and 
> after my serialization:
> 
> //initialization:
> XMLPlatformUtils::Initialize();
> XalanTransformer::initialize();
> 
> //DO SERIALIZATION WORK
> 
> //termination
> XalanTransformer::terminate();
> XMLPlatformUtils::Terminate();
> XalanTransformer::ICUCleanUp();
> 
> This violates the docs for initialize, which will be called here each 
> time I try to serialize, but my application does not crash with my basic 
> tests.

What you're doing is OK, so perhaps we need to make the documentation more 
explicit.  What you cannot do is call XalanTransformer::initialize() a 
second time, without an intervening call to XalanTransformer::terminate().

However, you should be very careful about calling 
XalanTransformer::ICUCleanup(), because it can cause problems.  Please read 
the documentation about static cleanup of the ICU, which is documented here:

http://icu.sourceforge.net/apiref/icu4c/uclean_8h.html#93f27d0ddc7c196a1da864763f2d8920

Xalan-C does not take care of calling u_init() for you -- you must do it 
yourself.

However, you might want to reconsider this strategy, because the amount of 
work done in both Xerces-C and Xalan-C during static initialization is 
significant, and doing it over and over again may not be the best strategy 
for optimal performance.

Dave