File: memory.html

package info (click to toggle)
python-pywcs 1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 11,888 kB
  • sloc: ansic: 31,441; lex: 6,170; fortran: 6,080; sh: 3,478; python: 3,122; sed: 408; makefile: 76
file content (39 lines) | stat: -rw-r--r-- 8,836 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>WCSLIB 4.8.2: Memory management</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="index.html">WCSLIB 4.8.2 and PGSBOX 4.8.2</a>
  </div>
</div>
<div class="contents">
<h1><a class="anchor" name="memory">Memory management </a></h1>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#2afc8255fde0965dddaa374463666d45" title="Default constructor for the wcsprm struct.">wcsini()</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 <a class="el" href="structwcsprm.html" title="Coordinate transformation parameters.">wcsprm</a> struct (using <a class="el" href="lin_8h.html#7ddea28768d99f01c6be1c71a4d8fe58" title="Default constructor for the linprm struct.">linini()</a> for certain of these). Note that <a class="el" href="wcs_8h.html#2afc8255fde0965dddaa374463666d45" title="Default constructor for the wcsprm struct.">wcsini()</a> does not allocate memory for the <em>tab</em> array - refer to the usage notes for <a class="el" href="wcshdr_8h.html#6dd857f7b61a5b349cc8af5a4b6d8a1c" 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#e5cc3f5d249755583403cdf54d2ebb91" title="Setup routine for the wcsprm struct.">wcsset()</a> (via <a class="el" href="lin_8h.html#5c01c0991c8d0c4437581a7c1453b09a" title="Setup routine for the linprm struct.">linset()</a>) also allocates memory for the <em>piximg</em> and <em>imgpix</em> arrays.</li></ul>
<p>
<ul>
<li><a class="el" href="lin_8h.html#7ddea28768d99f01c6be1c71a4d8fe58" title="Default constructor for the linprm struct.">linini()</a>: optionally allocates memory for the <em>crpix</em>, <em>pc</em>, and <em>cdelt</em> arrays in the <a class="el" href="structlinprm.html" title="Linear transformation parameters.">linprm</a> struct. If the <em>pc</em> matrix is not unity, <a class="el" href="lin_8h.html#5c01c0991c8d0c4437581a7c1453b09a" 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#2afc8255fde0965dddaa374463666d45" title="Default constructor for the wcsprm struct.">wcsini()</a> and <a class="el" href="wcs_8h.html#e5cc3f5d249755583403cdf54d2ebb91" title="Setup routine for the wcsprm struct.">wcsset()</a>.</li></ul>
<p>
<ul>
<li><a class="el" href="tab_8h.html#bb7920acdfb83179d3bac65035144c02" 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 <a class="el" href="structtabprm.html" title="Tabular transformation parameters.">tabprm</a> struct. <a class="el" href="tab_8h.html#e403ff0b740916989c7386728df001c8" 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#0f3501cc592c78e0f2cb9922466589f2" title="Destructor for the tabprm struct.">tabfree()</a> will then free it. <a class="el" href="tab_8h.html#519e8e4503f7c41c0f99e8597171c97f" 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></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>
<a class="el" href="wcs_8h.html#2afc8255fde0965dddaa374463666d45" title="Default constructor for the wcsprm struct.">wcsini()</a> maintains a record of memory it has allocated and this is used by <a class="el" href="wcs_8h.html#4ab38bc642c4656f62c43acf84a849f1" title="Destructor for the wcsprm struct.">wcsfree()</a> which <a class="el" href="wcs_8h.html#2afc8255fde0965dddaa374463666d45" title="Default constructor for the wcsprm struct.">wcsini()</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#4ab38bc642c4656f62c43acf84a849f1" title="Destructor for the wcsprm struct.">wcsfree()</a> separately if <a class="el" href="wcs_8h.html#2afc8255fde0965dddaa374463666d45" title="Default constructor for the wcsprm struct.">wcsini()</a> is invoked repeatedly on the same <a class="el" href="structwcsprm.html" title="Coordinate transformation parameters.">wcsprm</a> struct. Likewise, <a class="el" href="wcs_8h.html#e5cc3f5d249755583403cdf54d2ebb91" 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#7ddea28768d99f01c6be1c71a4d8fe58" title="Default constructor for the linprm struct.">linini()</a>, <a class="el" href="lin_8h.html#ef9ead7c6ea6ab08f3ba3fc6a1c30303" title="Destructor for the linprm struct.">linfree()</a>, and <a class="el" href="lin_8h.html#5c01c0991c8d0c4437581a7c1453b09a" title="Setup routine for the linprm struct.">linset()</a> and to <a class="el" href="tab_8h.html#bb7920acdfb83179d3bac65035144c02" title="Default constructor for the tabprm struct.">tabini()</a>, <a class="el" href="tab_8h.html#0f3501cc592c78e0f2cb9922466589f2" title="Destructor for the tabprm struct.">tabfree()</a>, and <a class="el" href="tab_8h.html#519e8e4503f7c41c0f99e8597171c97f" title="Setup routine for the tabprm struct.">tabset()</a>.<p>
A memory leak will result if a <a class="el" href="structwcsprm.html" title="Coordinate transformation parameters.">wcsprm</a>, <a class="el" href="structlinprm.html" title="Linear transformation parameters.">linprm</a> or <a class="el" href="structtabprm.html" title="Tabular transformation parameters.">tabprm</a> 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#4ab38bc642c4656f62c43acf84a849f1" title="Destructor for the wcsprm struct.">wcsfree()</a>, <a class="el" href="lin_8h.html#ef9ead7c6ea6ab08f3ba3fc6a1c30303" title="Destructor for the linprm struct.">linfree()</a> or <a class="el" href="tab_8h.html#0f3501cc592c78e0f2cb9922466589f2" title="Destructor for the tabprm struct.">tabfree()</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>
Beware of making a shallow copy of a <a class="el" href="structwcsprm.html" title="Coordinate transformation parameters.">wcsprm</a>, <a class="el" href="structlinprm.html" title="Linear transformation parameters.">linprm</a> or <a class="el" href="structtabprm.html" title="Tabular transformation parameters.">tabprm</a> 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#864c99fef9f3eee29085ce42d0ee0d64" title="Subimage extraction routine for the wcsprm struct.">wcssub()</a>, <a class="el" href="lin_8h.html#b8fc0ef6b34eb3327b13a00de78232b1" title="Copy routine for the linprm struct.">lincpy()</a> or <a class="el" href="tab_8h.html#87b3a2a84bab396a528af8382ce9ad04" title="Copy routine for the tabprm struct.">tabcpy()</a>. </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Tue Oct 4 19:02:31 2011 for WCSLIB 4.8.2 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>