wcslib (8.2.2)

(root)/
share/
doc/
wcslib-8.2.2/
html/
memory.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>WCSLIB: Memory management</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">WCSLIB<span id="projectnumber">&#160;8.2.2</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="index.html">WCSLIB 8.2.2 and PGSBOX 8.2.2</a></li>  </ul>
</div>
</div><!-- top -->
<div><div class="header">
  <div class="headertitle"><div class="title">Memory management</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The initialization routines for certain of the WCSLIB data structures allocate memory for some of their members:</p>
<ul>
<li><a class="el" href="wcs_8h.html#aab11243b60b10065fc85347bb3efa912" title="Default constructor for the wcsprm struct.">wcsinit()</a> optionally allocates memory for the <em>crpix</em>, <em>pc</em>, <em>cdelt</em>, <em>crval</em>, <em>cunit</em>, <em>ctype</em>, <em>pv</em>, <em>ps</em>, <em>cd</em>, <em>crota</em>, <em>colax</em>, <em>cname</em>, <em>crder</em>, and <em>csyer</em> arrays in the wcsprm struct (using <a class="el" href="lin_8h.html#afa85e4b255b144d2b806f51be0d36be2" title="Default constructor for the linprm struct.">lininit()</a> for certain of these). Note that <a class="el" href="wcs_8h.html#aab11243b60b10065fc85347bb3efa912" title="Default constructor for the wcsprm struct.">wcsinit()</a> does not allocate memory for the <em>tab</em> array - refer to the usage notes for <a class="el" href="wcshdr_8h.html#a6dd857f7b61a5b349cc8af5a4b6d8a1c" title="Tabular construction routine.">wcstab()</a> in <a class="el" href="wcshdr_8h.html">wcshdr.h</a>. If the <em>pc</em> matrix is not unity, <a class="el" href="wcs_8h.html#ae5cc3f5d249755583403cdf54d2ebb91" title="Setup routine for the wcsprm struct.">wcsset()</a> (via <a class="el" href="lin_8h.html#a5c01c0991c8d0c4437581a7c1453b09a" title="Setup routine for the linprm struct.">linset()</a>) also allocates memory for the <em>piximg</em> and <em>imgpix</em> arrays.</li>
<li><a class="el" href="lin_8h.html#afa85e4b255b144d2b806f51be0d36be2" title="Default constructor for the linprm struct.">lininit()</a>: optionally allocates memory for the <em>crpix</em>, <em>pc</em>, and <em>cdelt</em> arrays in the linprm struct. If the <em>pc</em> matrix is not unity, <a class="el" href="lin_8h.html#a5c01c0991c8d0c4437581a7c1453b09a" title="Setup routine for the linprm struct.">linset()</a> also allocates memory for the <em>piximg</em> and <em>imgpix</em> arrays. Typically these would be used by <a class="el" href="wcs_8h.html#aab11243b60b10065fc85347bb3efa912" title="Default constructor for the wcsprm struct.">wcsinit()</a> and <a class="el" href="wcs_8h.html#ae5cc3f5d249755583403cdf54d2ebb91" title="Setup routine for the wcsprm struct.">wcsset()</a>.</li>
<li><a class="el" href="tab_8h.html#abb7920acdfb83179d3bac65035144c02" title="Default constructor for the tabprm struct.">tabini()</a>: optionally allocates memory for the <em>K</em>, <em>map</em>, <em>crval</em>, <em>index</em>, and <em>coord</em> arrays (including the arrays referenced by <em>index</em>[]) in the tabprm struct. <a class="el" href="tab_8h.html#ae403ff0b740916989c7386728df001c8" title="Acquire tabular memory.">tabmem()</a> takes control of any of these arrays that may have been allocated by the user, specifically in that <a class="el" href="tab_8h.html#a0f3501cc592c78e0f2cb9922466589f2" title="Destructor for the tabprm struct.">tabfree()</a> will then free it. <a class="el" href="tab_8h.html#a519e8e4503f7c41c0f99e8597171c97f" title="Setup routine for the tabprm struct.">tabset()</a> also allocates memory for the <em>sense</em>, <em>p0</em>, <em>delta</em> and <em>extrema</em> arrays.</li>
<li><a class="el" href="dis_8h.html#a3e0e67bdd01c86eede779de63249c703" title="Default constructor for the disprm struct.">disinit()</a>: optionally allocates memory for the <em>dtype</em>, <em>dp</em>, and <em>maxdis</em> arrays. <a class="el" href="dis_8h.html#ad1bdf4497eb4513ca8431e1baa419041" title="Setup routine for the disprm struct.">disset()</a> also allocates memory for a number of arrays that hold distortion parmeters and intermediate values: <em>axmap</em>, <em>Nhat</em>, <em>offset</em>, <em>scale</em>, <em>iparm</em>, and <em>dparm</em>, and also several private work arrays: <em>disp2x</em>, <em>disx2p</em>, and <em>tmpmem</em>.</li>
</ul>
<p>The caller may load data into these arrays but must not modify the struct members (i.e. the pointers) themselves or else memory leaks will result.</p>
<p><a class="el" href="wcs_8h.html#aab11243b60b10065fc85347bb3efa912" title="Default constructor for the wcsprm struct.">wcsinit()</a> maintains a record of memory it has allocated and this is used by <a class="el" href="wcs_8h.html#a4ab38bc642c4656f62c43acf84a849f1" title="Destructor for the wcsprm struct.">wcsfree()</a> which <a class="el" href="wcs_8h.html#aab11243b60b10065fc85347bb3efa912" title="Default constructor for the wcsprm struct.">wcsinit()</a> uses to free any memory that it may have allocated on a previous invokation. Thus it is not necessary for the caller to invoke <a class="el" href="wcs_8h.html#a4ab38bc642c4656f62c43acf84a849f1" title="Destructor for the wcsprm struct.">wcsfree()</a> separately if <a class="el" href="wcs_8h.html#aab11243b60b10065fc85347bb3efa912" title="Default constructor for the wcsprm struct.">wcsinit()</a> is invoked repeatedly on the same wcsprm struct. Likewise, <a class="el" href="wcs_8h.html#ae5cc3f5d249755583403cdf54d2ebb91" title="Setup routine for the wcsprm struct.">wcsset()</a> deallocates memory that it may have allocated on a previous invokation. The same comments apply to <a class="el" href="lin_8h.html#afa85e4b255b144d2b806f51be0d36be2" title="Default constructor for the linprm struct.">lininit()</a>, <a class="el" href="lin_8h.html#aef9ead7c6ea6ab08f3ba3fc6a1c30303" title="Destructor for the linprm struct.">linfree()</a>, and <a class="el" href="lin_8h.html#a5c01c0991c8d0c4437581a7c1453b09a" title="Setup routine for the linprm struct.">linset()</a>, to <a class="el" href="tab_8h.html#abb7920acdfb83179d3bac65035144c02" title="Default constructor for the tabprm struct.">tabini()</a>, <a class="el" href="tab_8h.html#a0f3501cc592c78e0f2cb9922466589f2" title="Destructor for the tabprm struct.">tabfree()</a>, and <a class="el" href="tab_8h.html#a519e8e4503f7c41c0f99e8597171c97f" title="Setup routine for the tabprm struct.">tabset()</a>, and to <a class="el" href="dis_8h.html#a3e0e67bdd01c86eede779de63249c703" title="Default constructor for the disprm struct.">disinit()</a>, <a class="el" href="dis_8h.html#a83b98d0f6429f4f19024675645026187" title="Destructor for the disprm struct.">disfree()</a> and <a class="el" href="dis_8h.html#ad1bdf4497eb4513ca8431e1baa419041" title="Setup routine for the disprm struct.">disset()</a>.</p>
<p>A memory leak will result if a wcsprm, linprm, tabprm, or disprm struct goes out of scope before the memory has been <em>free'd</em>, either by the relevant routine, <a class="el" href="wcs_8h.html#a4ab38bc642c4656f62c43acf84a849f1" title="Destructor for the wcsprm struct.">wcsfree()</a>, <a class="el" href="lin_8h.html#aef9ead7c6ea6ab08f3ba3fc6a1c30303" title="Destructor for the linprm struct.">linfree()</a>, <a class="el" href="tab_8h.html#a0f3501cc592c78e0f2cb9922466589f2" title="Destructor for the tabprm struct.">tabfree()</a>, or <a class="el" href="dis_8h.html#a83b98d0f6429f4f19024675645026187" title="Destructor for the disprm struct.">disfree()</a> or otherwise. Likewise, if one of these structs itself has been <em>malloc'd</em> and the allocated memory is not <em>free'd</em> when the memory for the struct is <em>free'd</em>. A leak may also arise if the caller interferes with the array pointers in the "private" part of these structs.</p>
<p>Beware of making a shallow copy of a wcsprm, linprm, tabprm, or disprm struct by assignment; any changes made to allocated memory in one would be reflected in the other, and if the memory allocated for one was <em>free'd</em> the other would reference unallocated memory. Use the relevant routine instead to make a deep copy: <a class="el" href="wcs_8h.html#a864c99fef9f3eee29085ce42d0ee0d64" title="Subimage extraction routine for the wcsprm struct.">wcssub()</a>, <a class="el" href="lin_8h.html#ab8fc0ef6b34eb3327b13a00de78232b1" title="Copy routine for the linprm struct.">lincpy()</a>, <a class="el" href="tab_8h.html#a87b3a2a84bab396a528af8382ce9ad04" title="Copy routine for the tabprm struct.">tabcpy()</a>, or <a class="el" href="dis_8h.html#a42e03676a3def43ef6b936cd7beb4dd5" title="Copy routine for the disprm struct.">discpy()</a>. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Nov 29 2023 19:09:57 for WCSLIB by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8
</small></address>
</body>
</html>