🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.misc.discuss
Article #75706

Re: Why alloca()?

#75706
From: Kyle Jones
Date: Mon, 21 May 1990 13:35
28 lines
1930 bytes
Eric Schnoebelen writes:
 > I'm curious why (it seems like) all the gnu products seem to insist upon
 > using the alloca() function?  I was under the impression that it was
 > generally considered a vile, disgusting function and was generally
 > considered bad form to use it.

I've heard people go on and on in comp.lang.c about the evil of
using alloca(), but I remain unconvinced.  Certain memory
management takss are made much easier by using alloca(), as
opposed to malloc() and free().  Portability needn't suffer,
because portable substitutes for alloca() exist, and these can be used on
machines that don't support it.  But on machines that do support
it, alloca() is a big win.

 > Case in point.  I recently ported gdbm1.1 to System V R3.2.  The source
 > initially used alloca() in several places.  In doing so, it required me
 > to link in an additional library, that wouldn't obviously needed
 > normally.
 > 
 > With a little careful study, I was able to replace all occurrences of
 > alloca() with calls to malloc() and free().  This process took perhaps
 > an hour.  Why couldn't the original programmer have done this, and
 > created a much more portable program?

Is your code robust enough to reclaim the malloc'd memory, even
if the containing function does not exit normally, e.g. calls
longjmp()?  With alloca() the programmer doesn't have to worry
about this.
Technical Details
Message-ID: <1990May21.133554.12832@talos.pm.com>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!talos!kjones
References: <1990May19.044239.16031@egsner.cirr.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1025b4,57cdf436494e0ba9
X-Google-Attributes: gid1025b4,public
X-Google-ArrivalTime: 1990-05-21 08:32:54 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!talos!kjones
From: kjones@talos.pm.com (Kyle Jones)
Newsgroups: gnu.misc.discuss
Subject: Re: Why alloca()?
Message-ID: <1990May21.133554.12832@talos.pm.com>
Date: 21 May 90 13:35:54 GMT
References: <1990May19.044239.16031@egsner.cirr.com>
Reply-To: kyle@cs.odu.edu
Lines: 28
Posted: Mon May 21 14:35:54 1990