help needed about dynamic space allocation
Matt Landau
mlandau at Diamond.BBN.COM
Thu Nov 27 12:10:51 AEST 1986
In newsgroup comp.lang.c (article <332 at apple.UUCP>), turk at 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 at diamond.bbn.com 10 Moulton Street, Cambridge MA 02238
...seismo!diamond.bbn.com!mlandau (617) 497-2429
More information about the Comp.lang.c
mailing list