Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!Diamond!mlandau From: mlandau@Diamond.BBN.COM (Matt Landau) Newsgroups: comp.lang.c Subject: Re: help needed about dynamic space allocation Message-ID: <2431@slate.Diamond.BBN.COM> Date: Wed, 26-Nov-86 21:10:51 EST Article-I.D.: slate.2431 Posted: Wed Nov 26 21:10:51 1986 Date-Received: Wed, 26-Nov-86 22:59:10 EST References: <13802@amdcad.UUCP> <359@prairie.UUCP> <1046@lifia.UUCP> <715@dg_rtp.UUCP> <332@apple.UUCP> Reply-To: mlandau@Diamond.BBN.COM (Matt Landau) Organization: BBN Laboratories, Inc., Cambridge, MA Lines: 25 Summary: alloca is bad news In newsgroup comp.lang.c (article <332@apple.UUCP>), turk@apple.UUCP (Ken "Turk" Turkowski) writes: > >There have been numerous responses to get the declarations consistent, so I >won't belabor them here. > >However, I would like to point out the use of a function that can speed up the >program considerably when you are only allocating temporary variables. The >function is alloca(), and allocates memory from the stack, rather than from >the heap. The result is that allocation is simpler, and vanishes automatically >when you exit the routine. Well, there are going to be a lot of people pointing this out, but I thought I'd be the first :-) Alloca is nonstandard, nonportable, and doesn't exist on a lot of machines. In fact, the last time this subject came up was when a lot of people were having trouble porting Gnu Emacs bacause it used alloca(). At the time, I think the conclusion was that there exist machine architectures for which it is practically impossible to even implement it. The bottom line: Don't use alloca if you expect your code to port. -- Matt Landau BBN Laboratories, Inc. mlandau@diamond.bbn.com 10 Moulton Street, Cambridge MA 02238 ...seismo!diamond.bbn.com!mlandau (617) 497-2429