blob: d071c39217fe063ea06343949495a9c18b5144b9 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../skin/tigris.css" type="text/css">
<link rel="stylesheet" href="../../skin/mysite.css" type="text/css">
<link rel="stylesheet" href="../../skin/site.css" type="text/css">
<link media="print" rel="stylesheet" href="../../skin/print.css" type="text/css">
<title>Axis C++ Memory Management Guide</title>
</head>
<body bgcolor="white" class="composite">
<div id="banner">
<table width="100%" cellpadding="8" cellspacing="0" summary="banner" border="0">
<tbody>
<tr>
<td align="left">
<div class="groupLogo">
<a href="http://ws.apache.org/"><img border="0" class="logoImage" alt="The Apache WebServices Project" src="../../images/project-logo.jpg"></a>
</div>
</td><td align="right">
<div class="projectLogo">
<a href="http://ws.apache.org/axis/"><img border="0" class="logoImage" alt="The Apache Axis Project" src="../../images/axis.jpg"></a>
</div>
</td><td valign="top" rowspan="2" align="right" class="search">
<form target="_blank" action="http://www.google.co.jp/search" method="get">
<table summary="search" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#a5b6c6" colspan="3"><img height="10" width="1" alt="" src="../../skin/images/spacer.gif" class="spacer"></td>
</tr>
<tr>
<td colspan="3"><img height="8" width="1" alt="" src="../../skin/images/spacer.gif" class="spacer"></td>
</tr>
<tr>
<td><img height="1" width="1" alt="" src="../../skin/images/spacer.gif" class="spacer"></td><td nowrap="nowrap"><input value="ws.apache.org" name="sitesearch" type="hidden"><input value="ja" name="hl" type="hidden"><input value="UTF-8" name="ie" type="hidden"><input size="10" name="q" id="query" type="text"><img height="1" width="5" alt="" src="../../skin/images/spacer.gif" class="spacer"><input name="Search" value="検索" type="submit">
<br>WS を検索
</td><td><img height="1" width="1" alt="" src="../../skin/images/spacer.gif" class="spacer"></td>
</tr>
<tr>
<td colspan="3"><img height="7" width="1" alt="" src="../../skin/images/spacer.gif" class="spacer"></td>
</tr>
<tr>
<td class="bottom-left-thick"></td><td bgcolor="#a5b6c6"><img height="1" width="1" alt="" src="../../skin/images/spacer.gif" class="spacer"></td><td class="bottom-right-thick"></td>
</tr>
</table>
</form>
</td>
</tr>
</tbody>
</table>
</div>
<table width="100%" cellpadding="0" cellspacing="0" border="0" summary="nav" id="breadcrumbs">
<tbody>
<tr class="status">
<td><a href="http://www.apache.org/">Apache</a> | <a href="http://ws.apache.org/">WS</a><a href=""></a></td><td id="tabs">
<div class="tab">
<span class="selectedTab"><a class="base-selected" href="../../index.html">WebServices-Axis</a></span>
</div>
</td>
</tr>
</tbody>
</table>
<table id="main" width="100%" cellpadding="8" cellspacing="0" summary="" border="0">
<tbody>
<tr valign="top">
<td id="leftcol">
<div id="navcolumn">
<div class="menuBar">
<div class="menu">
<span class="menuLabel">Axis</span>
<div class="menuItem">
<a href="../../index.html">はじめに</a>
</div>
<div class="menuItem">
<a href="../../news.html">お知らせ</a>
</div>
<div class="menuItem">
<a href="http://wiki.apache.org/ws/ja/axis">FAQ/Wiki</a>
</div>
<div class="menu">
<span class="menuLabel">活動に参加</span>
<div class="menuItem">
<a href="../../overview.html">概要</a>
</div>
<div class="menuItem">
<a href="../../cvs.html">CVS リポジトリ</a>
</div>
<div class="menuItem">
<a href="../../mail.html">メーリングリスト</a>
</div>
<div class="menuItem">
<a href="../../ref.html">リファレンスライブラリ</a>
</div>
<div class="menuItem">
<a href="../../bugs.html">バグ</a>
</div>
<div class="menuItem">
<a href="../../howtobuild.html">サイト構築方法</a>
</div>
</div>
<div class="menu">
<span class="menuLabel">Axis (Java)</span>
<div class="menuItem">
<a href="../../java/index.html">ドキュメント</a>
</div>
<div class="menuItem">
<a href="../../java/install.html">インストール</a>
</div>
<div class="menuItem">
<a href="../../java/user-guide.html">ユーザガイド</a>
</div>
<div class="menuItem">
<a href="../../java/developers-guide.html">開発者ガイド</a>
</div>
<div class="menuItem">
<a href="../../java/integration-guide.html">統合ガイド</a>
</div>
<div class="menuItem">
<a href="../../java/architecture-guide.html">アーキテクチャガイド</a>
</div>
<div class="menuItem">
<a href="../../java/reference.html">リファレンスガイド</a>
</div>
<div class="menuItem">
<a href="../../java/reading.html">読書ガイド</a>
</div>
<div class="menuItem">
<a href="../../java/requirements.html">要件</a>
</div>
</div>
<div class="menu">
<span class="menuLabel">Axis (C++)</span>
<div class="menuItem">
<a href="../../cpp/index.html">Axis C++ 最新版</a>
</div>
<div class="menuItem">
<a href="../../cpp/documentation.html">ドキュメント</a>
</div>
<div class="menuItem">
<a href="../../cpp/download.html">ダウンロード</a>
</div>
<div class="menuItem">
<a href="http://wiki.apache.org/ws/FrontPage/AxisCPP">Wiki ページ [英語]</a>
</div>
<div class="menuItem">
<a href="../../cpp/who.html">メンバ紹介</a>
</div>
</div>
<div class="menu">
<span class="menuLabel">ダウンロード</span>
<div class="menuItem">
<a href="../../releases.html">リリース</a>
</div>
<div class="menuItem">
<a href="../../interim.html">暫定版</a>
</div>
<div class="menuItem">
<a href="http://cvs.apache.org/viewcvs/ws-axis/">ソースコード [英語]</a>
</div>
</div>
<div class="menu">
<span class="menuLabel">翻訳</span>
<div class="menuItem">
<a href="http://ws.apache.org/axis/jp/">日本語</a>
</div>
</div>
<div class="menu">
<span class="menuLabel">関連プロジェクト</span>
<div class="menuItem">
<a href="http://ws.apache.org/wsif/">WSIF [英語]</a>
</div>
<div class="menuItem">
<a href="http://cvs.apache.org/viewcvs/*checkout*/ws-wsil/java/README.htm">WSIL [英語]</a>
</div>
<div class="menuItem">
<a href="http://www-124.ibm.com/developerworks/projects/wsdl4j/">WSDL4J [英語]</a>
</div>
<div class="menuItem">
<a href="http://www.uddi4j.org/">UDDI4J [英語]</a>
</div>
</div>
<div class="menu">
<span class="menuLabel">その他</span>
<div class="menuItem">
<a href="../../who.html">メンバ紹介</a>
</div>
<div class="menuItem">
<a href="../../contact.html">連絡先</a>
</div>
<div class="menuItem">
<a href="../../legal.html">法関連</a>
</div>
<div class="menuItem">
<a href="../../docs.html">メモ/ドキュメント</a>
</div>
</div>
</div>
</div>
</div>
</td><td>
<div id="bodycol">
<div class="app">
<div align="center">
<h1>Axis C++ Memory Management Guide</h1>
</div>
<div class="h3">
<div class="h3">
<h3>Axis C++ Memory Management Guide</h3>
</div>
<br>
<em>1.0 Version</em>
<br>
<em>Feedback: axis-c-dev@ws.apache.org</em>
<div class="h4">
<h4>Introduction</h4>
</div>
<p>This guide records the memory management semantics and some of the rationales of the design decisions on which memory management semantics are based on. Being a C/C++ application, it is a must that all users as well as developers have a clear understanding on how to deal with memory allocation and deallocation.</p>
<p>The allocation and deallocation mechanisms are centered around the serializer and deserializer operations in Axis C++. At the moment, because Axis C++ support both C and C++ clients and services, the deserializer uses <em>malloc()</em> for memory allocation. Hence C++ users may have to live with <em>free()</em> (instead of <em>delete</em>) for deallocation. Of course one could still use delete from C++ programs, however this may not guarantee the cleanest memory deallocation.</p>
<div class="h4">
<h4>Allocation/De-allocation Semantics</h4>
</div>
<div class="h2">
<h2>Parameters</h2>
</div>
<em>malloc()</em><em>new</em>
<div class="h2">
<h2>Other Objects</h2>
</div>
<ol>
<li>Any outbound objects created, either by a client application or by a handler, must be managed by the creator him(her)self. The Axis C++ engine does not delete any objects (HeaderBlocks, Attributes, BasicNodes etc.).</li>
<li>Any inbound objects that are created by the Axis C++ Engine as a result of deserialization should be deallocated by a target handler or the client application. Axis C++ Engine deallocates only the headerblocks that will remain in the deserializer (headerblocks with no target handler).</li>
</ol>
<div class="h2">
<h2>Return Values</h2>
</div>
<p>The values returned by the Axis C++ engine must be memory cleaned by the user written code. The C++ code generated by the WSDL2Ws tool does contain destructors. However, at the moment, it is not gauranteed that the destructor of a generated class would clean all the pointer members (Some members are cleaned while others are not). Hence the users must have a look at the generated code to understand the semantics of memory cleaning. In case of C code, of course the user must take care of memory cleaning.</p>
<p>Please note that in case of arrays, both for C and C++, the Axis C++ engine returns a struct. Hence it is a must that the memory is cleaned properly.<br> C++ Example:<br>
</p>
<pre> // testing echoIntegerArray
xsd__int_Array arrint; // Parameter for method call
arrint.m_Array = new int[ARRAYSIZE];
arrint.m_Size = ARRAYSIZE;
for (x = 0; x &lt; ARRAYSIZE; x++)
{
arrint.m_Array[x] = x;
}
printf ("invoking echoIntegerArray...\n");
xsd__int_Array arrintResult = ws.echoIntegerArray (arrint);
// Deal with the return value
if (arrintResult.m_Array != NULL)
{
printf ("successful\n");
// Clean memory of the returned array
free(arrintResult.m_Array);
}
else
printf ("failed\n");
// Clean memory allocated for parameter
delete [] arrint.m_Array;
</pre>
<br>
<div class="h4">
<h4>Dealing with SOAP Headers</h4>
</div>
<div class="h2">
<h2>From Stubs</h2>
</div>
<p>IHeaderBlock is a virtual class that defines the interface to deal with SOAP headers. You can create an IHeaderBlock at the client side using the API provided with Stub classes.<br>
</p>
<pre>IHeaderBlock* Stub::createSOAPHeaderBlock(AxisChar * pachLocalName, AxisChar * pachUri);
</pre>
<p>
<strong>Note 1</strong>: It is advisable that if a user wants to delete a Hheader Block, (s)he uses the API provided by the Stub class to do so.<br>
</p>
<pre>void deleteCurrentSOAPHeaderBlock();
</pre>
<br>
<p>
<strong>Note 2</strong>: IHeaderBlock destructor will take care of the Header Block member variables and cleans them; BasicNodes (i.e its children) and the Attributes.<br>
</p>
<div class="h2">
<h2>From Handlers</h2>
</div>
<p>If the Header Blocks are created within a Handler then it is the responsibility of the Handler writer to clean those. For that the user can write the cleanup code either in the fini() method or in the destructor of the Handler, depending on the following situations</p>
<ul>
<li>If it is a session handler which needs to maintain its state, then the cleanup has to be done in the destructor.</li>
<li>If it is a request type handler the clean up can be done in the fini() mehtod of the Handler. Here the writer has to explicitly write the clean up code.</li>
</ul>
<p>If a target handler access a Header Block created by the deserializer then it is the responsibility of the Handler to delete it.</p>
<div class="h4">
<h4>Open Issues</h4>
</div>
<p>As C++ is an object oriented language, one would ideally like to leverage constructors and destructors for memory management. However, the Axis C++ engine uses structs in some cases (e.g. Arrays) and uses <em>malloc()</em> to allocate memory. Hence the C++ programmer would be forced to use <em>free()</em> at times. When using <em>malloc()</em> and <em>free()</em> constructors and destructors are not called. However, as the Axis C++ engine currently supports both C and C++, it is not simple to replace all <em>malloc()</em> with <em>new</em> or <em>free()</em> with <em>delete</em>. At the same time, there are some places where <em>new</em> and <em>delete</em> are being used. They too cannot be replaced with <em>malloc()</em> and <em>free()</em> overnight. This memory management complexity is the price paid for dual support of C and C++. Efforts are under way to clean up the memory management mix-ups and still support both C and C++. Currently the proposed solution is to make the Axis C++ engine pure C++ and use a wrapper mechanism to support C.</p>
<p>When an array is de-serialized it uses C style memory re-allocation mechanism in the present code. C++ does not support <em>realloc()</em> and if we use <em>new</em> instead we have to allocate fresh memory blocks each time we need to increase the array size. This can be more expensive than using <em>realloc()</em>. Again the price paid for efficiency is that one has to use <em>free()</em> and not <em>delete []</em> from C++ code.</p>
<div id="pdf" align="right">
<a href="mem-management.pdf"><img alt="PDF" src="../../skin/images/pdfdoc.gif" class="skin"><br>
PDF</a>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<div id="footer">
<table summary="footer" cellspacing="0" cellpadding="4" width="100%" border="0">
<tbody>
<tr>
<td colspan="2">
<div align="center">
<div class="copyright">
Copyright &copy; 2000-2005&nbsp;The Apache Software Foundation. All rights reserved.
</div>
</div>
</td>
</tr>
<tr>
<td align="left"></td><td align="right">
<div align="right">
<div class="credit"></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>