Related articles |
---|
[3 earlier articles] |
Re: What's wrong with alloca() ? preston@dawn.cs.rice.edu (1991-12-22) |
Re: What's wrong with alloca() ? wjw@eb.ele.tue.nl (1991-12-23) |
Re: What's wrong with alloca() ? David.Chase@Eng.Sun.COM (1991-12-23) |
Re: What's wrong with alloca() ? pcg@aber.ac.uk (1991-12-26) |
Re: What's wrong with alloca() ? wicklund@intellistor.com (1991-12-30) |
Re: What's wrong with alloca() ? wws@renaissance.cray.com (1991-12-30) |
Re: What's wrong with alloca() ? jfc@athena.mit.edu (1991-12-31) |
Re: What's wrong with alloca() ? GORMAN_B@prime1.lancashire-poly.ac.uk (Barry Gorman) (1992-01-03) |
Re: What's wrong with alloca() ? rankin@eql.caltech.edu (1992-01-05) |
Re: What's wrong with alloca() ? pcg@aber.ac.uk (1992-01-05) |
Re: What's wrong with alloca() ? barmar@think.com (1992-01-06) |
Newsgroups: | comp.compilers |
From: | jfc@athena.mit.edu (John F Carr) |
Keywords: | storage |
Organization: | Massachusetts Institute of Technology |
References: | 91-12-075 91-12-089 |
Date: | Tue, 31 Dec 1991 16:46:10 GMT |
In article 91-12-089
wws@renaissance.cray.com (Walter Spector) writes:
>Note that the routines 'array' and 'another1' are local to routine 'junk'.
>They are allocated upon entry (doesn't matter if it is the stack or heap)
>and deallocated upon exit.
It does matter where they are allocated: setjmp and longjmp are complicated
if they have to maintain a list of objects to be freed. If variable size
arrays are allocated on the heap, there must be a list of such objects where
longjmp can read it (the simplest implementation appears to be to keep the
objects as a linked list, with a word in the stack frame pointing to the head
of the list). longjmp on the IBM RT, which uses the stack for alloca, is 4
instructions long (2 instructions to restore registers, 1 to copy the return
value, and 1 to return).
Another problem with variable size objects on the stack is that out of memory
is typically signaled by a segmentation violation (or similar fatal error)
instead of by a NULL return from malloc. Constant size objects are subject
to the same problem in theory, but in practice very few C programs that do
not call alloca() reach the stack memory limit. (This turned out to be the
cause of a mysterious X server crash: X uses alloca for temporary space, and
it is possible to send a single request to the X server that makes it try to
allocate more space than the default stack limit on our BSD workstations).
--
John Carr (jfc@athena.mit.edu)
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.