Sophie

Sophie

distrib > CentOS > 6 > i386 > by-pkgid > 2c51d8eb79f8810ada971ee8c30ce1e5 > files > 4124

kernel-doc-2.6.32-71.14.1.el6.noarch.rpm

<?xml version="1.0" encoding="ANSI_X3.4-1968" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968" /><title>... And the Destructor?</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><link rel="home" href="index.html" title="Writing an ALSA Driver" /><link rel="up" href="ch05.html" title="Chapter&#160;5.&#160;PCM Interface" /><link rel="prev" href="ch05s03.html" title="Constructor" /><link rel="next" href="ch05s05.html" title="Runtime Pointer - The Chest of PCM Information" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">... And the Destructor?</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch05s03.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;5.&#160;PCM Interface</th><td width="20%" align="right">&#160;<a accesskey="n" href="ch05s05.html">Next</a></td></tr></table><hr /></div><div class="section" title="... And the Destructor?"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="pcm-interface-destructor"></a>... And the Destructor?</h2></div></div></div><p>
        The destructor for a pcm instance is not always
      necessary. Since the pcm device will be released by the middle
      layer code automatically, you don't have to call the destructor
      explicitly.
      </p><p>
        The destructor would be necessary if you created
        special records internally and needed to release them. In such a
        case, set the destructor function to
        pcm-&gt;private_free: 

        </p><div class="example"><a id="id2946633"></a><p class="title"><b>Example&#160;5.2.&#160;PCM Instance with a Destructor</b></p><div class="example-contents"><pre class="programlisting">

  static void mychip_pcm_free(struct snd_pcm *pcm)
  {
          struct mychip *chip = snd_pcm_chip(pcm);
          /* free your own data */
          kfree(chip-&gt;my_private_pcm_data);
          /* do what you like else */
          ....
  }

  static int __devinit snd_mychip_new_pcm(struct mychip *chip)
  {
          struct snd_pcm *pcm;
          ....
          /* allocate your own data */
          chip-&gt;my_private_pcm_data = kmalloc(...);
          /* set the destructor */
          pcm-&gt;private_data = chip;
          pcm-&gt;private_free = mychip_pcm_free;
          ....
  }

          </pre></div></div><p><br class="example-break" />
      </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch05s03.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="ch05.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="ch05s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Constructor&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Runtime Pointer - The Chest of PCM Information</td></tr></table></div></body></html>