[gst-devel] use of g_alloca

Andy Wingo wingo at pobox.com
Mon Sep 12 06:59:22 CEST 2005


Hi Dave,

A slightly caustic mail follows.

On Sun, 2005-09-11 at 12:02 -0700, David Schleef wrote:
> On Sun, Sep 11, 2005 at 04:24:54PM +0200, Stefan Kost wrote:
> > what is the problem with using g_alloca() [1][2]?
> 
[.. security concerns ...]

I don't see how these children-playing-with-knives arguments are any
different than anything else we do in C.

> Using alloca() tends to lead to stack overflows

Etc, etc, only if you're a moron though. We're not talking about
allocating buffer data on the stack.

>   Using the allocated
> area tends to trash the cache as well, depending on CPU, so it
> often isn't faster than malloc.

This is interesting, I would like to read more about this.

(This is an instance of a general pattern of you saying interesting
things without any references or supporting statements. Moses, what
exactly did you do up there on the mountain with God? Seriously.)

> Oh yeah, it's also non-portable, and the code that emulates alloca()
> leaks like crazy.

(1) It's supported on all systems that GCC targets, and (2) it says
clearly in its docs that you have to periodically g_alloca(0) to clean
up.

alloca(3) is fast and has good realtime characteristics. It also won't
leak memory. I think that if it occurs to a programmer to use it, people
should review it, but there's no a priori reason to replace it with
malloc.

Regards,
-- 
Andy Wingo
http://wingolog.org/





More information about the gstreamer-devel mailing list