Subj : Re: OO compilers and efficiency To : comp.programming From : Rob Thorpe Date : Mon Jul 25 2005 10:37 am Chris Dollin wrote: > Rob Thorpe wrote: > > > SML/OCaml - Only allocate simple things on the Stack > > Pop11 - Couldn't find out about this one, I'll take your word on it. > > Lisp - Allocates anything you want on the stack if the programmer > > specifies "dynamic-extent" but will cannot do so automatically. > > Smalltalk - Smalltalk "contexts" are held in a stack, but this makes > > little odds since "new:" is not a language intrinsic, it's a class > > method. > > > > So, I've successfully proved myself wrong. > > > > (Think of this as a mid-thread batting collapse. I'll make it up in > > the second test, promise.) > > I'm sure there's stuff out there on automatic stack-allocation for > Lisp - I remember noises about it from years back - so perhaps this > was just the first innings? In Common Lisp you can't really do this. Once a symbol has being brought into existence it can be referenced anywhere and it can be brought together with a function in a closure. If the compiler can prove that a symbol and the data tied to it can't be referenced outside a certain scope then it could allocate it as it likes, but doing this is very difficult. It may be possible for individual variables, but not likely for what I called "things" above. If any part of the data is passed into the program proper then it must be on the heap so GC can be done. So, to allow the programmer to do stack allocation the "dynamic-extent" form is used. This creates the possibility of making code that doesn't create significant garbage, useful in things like OSes and inner-loops. I think the situation is different in Scheme and the stack can be used more widely, but I haven't looked into it much. Both languages use the stack for function calls. .