<?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 5. 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> </td><th width="60%" align="center">Chapter 5. PCM Interface</th><td width="20%" align="right"> <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->private_free: </p><div class="example"><a id="id2946633"></a><p class="title"><b>Example 5.2. 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->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->my_private_pcm_data = kmalloc(...); /* set the destructor */ pcm->private_data = chip; pcm->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> </td><td width="20%" align="center"><a accesskey="u" href="ch05.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch05s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Constructor </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Runtime Pointer - The Chest of PCM Information</td></tr></table></div></body></html>