| <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| <html> |
| <head> |
| <title>ASF: Programming Tips</title> |
| <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> |
| <meta http-equiv="Content-Style-Type" content="text/css" /> |
| <link rel="stylesheet" type="text/css" href="resources/apache-xalan.css" /> |
| </head> |
| <!-- |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| --> |
| <body> |
| <div id="title"> |
| <table class="HdrTitle"> |
| <tbody> |
| <tr> |
| <th rowspan="2"> |
| <a href="../index.html"> |
| <img alt="Trademark Logo" src="resources/XalanC-Logo-tm.png" width="190" height="90" /> |
| </a> |
| </th> |
| <th text-align="center" width="75%"> |
| <a href="index.html">Xalan-C/C++ Version 1.11</a> |
| </th> |
| </tr> |
| <tr> |
| <td valign="middle">Programming Tips</td> |
| </tr> |
| </tbody> |
| </table> |
| <table class="HdrButtons" align="center" border="1"> |
| <tbody> |
| <tr> |
| <td> |
| <a href="http://www.apache.org">Apache Foundation</a> |
| </td> |
| <td> |
| <a href="http://xalan.apache.org">Xalan Project</a> |
| </td> |
| <td> |
| <a href="http://xerces.apache.org">Xerces Project</a> |
| </td> |
| <td> |
| <a href="http://www.w3.org/TR">Web Consortium</a> |
| </td> |
| <td> |
| <a href="http://www.oasis-open.org/standards">Oasis Open</a> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div id="navLeft"> |
| <ul> |
| <li> |
| <a href="resources.html">Resources</a> |
| <br /> |
| </li> |
| <li> |
| <a href="../index.html">Home</a> |
| </li></ul><hr /><ul> |
| <li> |
| <a href="index.html">Xalan-C++ 1.11</a> |
| </li> |
| <li> |
| <a href="whatsnew.html">What's New</a> |
| </li> |
| <li> |
| <a href="license.html">Licenses</a> |
| </li></ul><hr /><ul> |
| <li> |
| <a href="overview.html">Overview</a> |
| </li> |
| <li> |
| <a href="charter.html">Charter</a> |
| </li></ul><hr /><ul> |
| <li> |
| <a href="download.html">Download</a> |
| </li> |
| <li> |
| <a href="buildlibs.html">Build Libraries</a> |
| </li> |
| <li> |
| <a href="install.html">Installation</a> |
| </li> |
| <li> |
| <a href="builddocs.html">Build Documents</a> |
| </li></ul><hr /><ul> |
| <li> |
| <a href="samples.html">Sample Apps</a> |
| </li> |
| <li> |
| <a href="commandline.html">Command Line</a> |
| </li> |
| <li> |
| <a href="usagepatterns.html">Usage Patterns</a> |
| </li></ul><hr /><ul> |
| <li>Programming<br /> |
| </li> |
| <li> |
| <a href="extensions.html">Extensions</a> |
| </li> |
| <li> |
| <a href="extensionslib.html">Extensions Library</a> |
| </li> |
| <li> |
| <a href="apiDocs/index.html">API Reference</a> |
| </li></ul><hr /><ul> |
| <li> |
| <a href="faq.html">Xalan-C FAQs</a> |
| </li></ul><hr /><ul> |
| <li> |
| <a href="whatsnew.html#bugs">Bugs</a> |
| </li> |
| <li> |
| <a href="http://xalan.apache.org/old/xalan-j/test/run.html#how-to-run-c">Testing</a> |
| </li> |
| <li> |
| <a href="secureweb.html">Web Security</a> |
| </li> |
| </ul> |
| </div> |
| <div id="content"> |
| <h2>Programming Tips</h2> |
| <ul> |
| <li> |
| <a href="#intro">Introduction</a> |
| </li> |
| <li> |
| <a href="#memory">Pluggable Memory Management</a> |
| </li> |
| <li> |
| <a href="#more">More topics</a> |
| </li> |
| </ul> |
| |
| <a name="intro"></a> |
| <p align="right" size="2"> |
| <a href="#content">(top)</a> |
| </p> |
| <h3>Introduction</h3> |
| <p>This section was created to guide users on how to use some of the new features going into the Xalan |
| source code base. Some of the features discussed in this section are based on feedback and questions |
| posted on the xalan-c-users newsgroup. This section will cover the benefits of certain features |
| and provide users with programming hints on how to utilize the features in their applications.</p> |
| |
| |
| <a name="memory"></a> |
| <p align="right" size="2"> |
| <a href="#content">(top)</a> |
| </p> |
| <h3>Pluggable Memory Management</h3> |
| <p>Pluggable memory management was added as a new feature in Xalan-C Version 1.8;. This feature introduces an |
| object called MemoryManager which allows applications with stricter memory management requirements to |
| utilize a more efficient allocation method. This MemoryManager object can be applied to |
| each processor instance, thus recovery procedures from memory leaks or processor crashes will be applied to |
| the associated instance only.</p> |
| <p>The memory management model is similar to the memory management feature provided by the Xerces-C XML Parser.</p> |
| <p align="right" size="2"> |
| <a href="#content">(top)</a> |
| </p> |
| <h4>How To Use This Feature</h4> |
| <p>To apply memory management to your application, the MemoryManager object needs to be specified in two |
| stages:</p> |
| <ul> |
| <li>At initialization phase. The purpose of specifying a MemoryManager object during initialization is to |
| create a separate memory manager for the overall application. Example of how this can be done is shown in |
| the example below<br /> |
| <br /> |
| <blockquote class="source"> |
| <pre> |
| // Initialization step |
| static void XalanTransformer::initialize(MemoryManager* initMemoryManager=0); |
| </pre> |
| </blockquote> |
| </li> |
| <li>Creation of a transformer instance. This creates a unique memory manager for the instance of the |
| processor. This step is optional. If no memory manager is provided, the global heap is used as the memory |
| source. Example of this is shown below:<br /> |
| <br /> |
| <blockquote class="source"> |
| <pre> |
| // Create instance of XalanTransformer |
| MemoryManager memMgrA; // memory manager object |
| XalanTransformer transformerA(&memMgrA); |
| |
| MemoryManager memMgrB; |
| XalanTransformer transformerB(&memMgrB); |
| XalanTransformer transformerC(&memMgrB); // Uses same memory manager object as transformerB |
| XalanTransformer transformerD; // Uses default static memory manager |
| </pre> |
| </blockquote> |
| </li> |
| </ul> |
| <p>The above method demonstrates how users can apply the basic pluggable memory management feature. Users |
| also have the option of implementing their own memory manager. This can be done by simply writing methods |
| for:</p> |
| <blockquote class="source"> |
| <pre> |
| // Method for allocating memory |
| void* allocate(size_t size); |
| </pre> |
| </blockquote> |
| <p>and</p> |
| <blockquote class="source"> |
| <pre> |
| // Method for deallocating memory |
| void deallocate(void *p); |
| </pre> |
| </blockquote> |
| <p>For an example of how to use this feature, please see the <a href="samples.html#simpletransform"> |
| SimpleTransform</a> sample that has been provided in the binary distributions.</p> |
| |
| |
| |
| <a name="more"></a> |
| <p align="right" size="2"> |
| <a href="#content">(top)</a> |
| </p> |
| <h3>More Topics</h3> |
| <p>Please feel free to give us feedback on what topics you would like to see.</p> |
| <p>Send comments to <a href="mailto:dev@xalan.apache.org">Xalan Development Mailing List</a>.</p> |
| |
| |
| <p align="right" size="2"> |
| <a href="#content">(top)</a> |
| </p> |
| </div> |
| <div id="footer">Copyright © 1999-2012 The Apache Software Foundation<br />Apache, Xalan, and the Feather logo are trademarks of The Apache Software Foundation<div class="small">Web Page created on - Tue 2012-10-09</div> |
| </div> |
| </body> |
| </html> |