[gst-devel] We should use alloca(3).

Andy Wingo wingo at pobox.com
Thu Apr 8 07:28:14 CEST 2004


On Sat, 2004-04-03 at 03:36, David Schleef wrote:
> On Mon, Mar 29, 2004 at 08:18:15PM +0200, Andy Wingo wrote:
> > Hey folks,
> > 
> > I think we should promote the use of alloca(3).

I'll change the recommendation to g_alloca, since it doesn't play with
our build.

> Use of alloca() causes subtle bugs, one of them being that failed
> allocations cause segfaults.

Allow me to give a use case: a multi-in, single-out element that gets
linked and unlinked on the sink end during PLAYING. It's difficult to
avoid a malloc here for a small array of pointers-to-gstbuffer or the
like. It's like a GNU C variable array, but more portable.

> Another problem is that alloca() tends to make stack smashing a lot
>  easier.  I think these are both problems we'd like to avoid,
>  especially since some day, GStreamer may be expected to handle
>  untrusted media files.

Interesting point.

> Also, GStreamer doesn't chase CPU cycles.  It's just not worth it
> for code that is executed on the order of once per iteration.  If
> it were ~1000 or ~1e6 times per iteration, I would care.

I'm looking for ways to avoid malloc. malloc breaks the realtime
characteristics of a GStreamer graph. It's not a question of CPU
consumption, it's about RT operation.

Alternately, we could develop a realtime allocation library (or steal
SuperCollider's).

Regards,
-- 
Andy Wingo <wingo at pobox.com>




More information about the gstreamer-devel mailing list