Search code examples
clinuxaudioalsa

What is difference between snd_pcm_hw_params_alloca() and snd_pcm_hw_params_malloc()?


I have seen some codes for capture/playback using alsa api. Some of them are using snd_pcm_hw_params_malloc() while some are using snd_pcm_hw_params_alloca().

What is the difference between them other than one is function and one is macro. Is snd_pcm_hw_params_alloca() macro replaced by snd_pcm_hw_params_malloc() ?


Solution

  • snd_pcm_hw_params_alloca() uses alloca() to allocate the structure on the stack. This means that it is automatically freed when your function returns.

    snd_pcm_hw_params_malloc() uses malloc(). You are responsible to call snd_pcm_hw_params_free() when it is no longer needed.