class CVersitTlsData : public CBase |
Versit thread local storage.
This class provides a performance improvement by allowing a CVersitUnicodeUtils instance to be shared between parsers operating in the same thread, so that a new instance does not have to be created for each parser. A pointer to the unicode utilities object is held in thread local storage: a single word (32bits) of data. Each unicode utilities object is managed by an instance of this class.
Every time a parser is created, CVersitParser::ConstructL() calls the CVersitTlsData constructor, and when the parser is destroyed the CVersitTlsData destructor is called. If a CVersitTlsData object exists, the constructor returns a pointer to it, otherwise a new one is constructed. The CVersitTlsData object is only destroyed when no more parsers refer to it: a count is kept, which is incremented every time the constructor is called and decremented each time the destructor is called, and the object is only destroyed when the count reaches zero.
This class provides an additional major performance improvement if you are sequentially constructing and destructing multiple parsers. By default, when the count of parsers reaches zero, the thread local storage object is destroyed (even if the thread has not finished). However, by using the technique described below, the thread local storage object, and therefore the unicode utilities object, can be made to persist, significantly reducing the overhead of sequentially constructing and destructing parsers.
The constructor needs to be called an extra time before creating any parsers, and the destructor needs to be called an extra time once the parsers have been destroyed. This has the effect of adding one to the reference count so that during all the parser construction and deletion the count never hits zero, which would trigger the TLS object's destruction.
This can be implemented as follows:
CVersitTlsData* versitTLS = CVersitTlsData::VersitTlsDataL();
2. Create and delete the parsers.
delete versitTLS;
Public Member Functions | |
---|---|
CVersitAdditionalStorage & | AdditionalStorage() |
IMPORT_C void | CloseVersitTlsData() |
CVersitUnicodeUtils & | UnicodeUtils() |
IMPORT_C void | VersitTlsDataClose() |
IMPORT_C CVersitTlsData & | VersitTlsDataL() |
Private Member Functions | |
---|---|
~CVersitTlsData() | |
void | ConstructL() |
CVersitTlsData * | NewL() |
Private Attributes | |
---|---|
CVersitAdditionalStorage * | iAdditionalStorage |
TInt | iRefCount |
CVersitUnicodeUtils * | iUnicodeUtils |
CVersitAdditionalStorage & | AdditionalStorage | ( | ) | [inline] |
Returns a pointer to the additional property storage object.
CVersitUnicodeUtils & | UnicodeUtils | ( | ) | [inline] |
Returns a pointer to the current Unicode utilities object.
IMPORT_C void | VersitTlsDataClose | ( | ) |
Frees all resources owned by the object if there are no parsers left (i.e. created and not destroyed), prior to its destruction.
IMPORT_C CVersitTlsData & | VersitTlsDataL | ( | ) | [static] |
Returns a reference to the current Thread Local Storage (TLS) object or, if there isn't one, it creates one.
If a new TLS object is being created, the object also creates (and owns) a Unicode utilities object, and creates a Unicode converter using this object.
If creating a new object, it calls the CVersitUnicodeUtils constructor followed by CVersitUnicodeUtils::CreateConverterL().
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.