Skip to content.

logo Stackless Python


Personal tools
Views

C stack

last edited 9 months ago by rmtew

Every C program uses memory areas that are called stack and heap. The heap is the memory that can be used by a program via memory management functions. The stack is the memory area, that contains the local variables. On every function call, a stack area is created. Especially with recursive functions, the stack size can grow unbounded. This is a problem, since the stack size cannot be changed, it is a limited resource.

Stackless has several techniques to deal with this problem.

  • In Stackless 1.0, C stack was saved by avoiding its usage wherever possible.
  • In Stackless 2.0, C stack was saved by storing pieces in heap-allocated memory and re-using the same stack.
  • In Stackless 3.0, both techniques are combined.

XXX lead to some more detailed pages for technically curious people


Stackless C --dougransom, Sat, 13 Oct 2007 03:24:28 +0200

I have always thought it would be interesting to modify a C compiler to avoid the operating system stack. Each "C" stack frame would be allocated off a heap (maybe a different one than malloc?). It shouldn't be too hard, nor violate the C standard. The stack frames could be collected with a conservative garbage collector, allowing for some interesting optimizations (like function return value optimzation via continuations) and possibly allow coroutines or the lightweight tasks of stackless.

Wiki comments --rmtew, Sat, 23 Feb 2008 19:38:53 +0100

Wiki comments do not as far as I know, cause anyone to be notified that they have been made. The best place to make them is on the mailing list, as they will then be seen.

 

Powered by Plone