Re: Re: Pragmatic Requirements Summary : update
Brian Hurt <[email protected]> Tue, 5 Aug 2003 09:53:46 -0500 (CDT)
| Newsgroups | gmane.comp.programming.pragmatic |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 5 Aug 2003, Aryeh M. Friedman wrote:
> A internal strawman we are tossing around right now calls for
> each block to have it's own stack... Initally this was only for
> concurrancy but it might be useful for other stuff as you point out
> here... ideas on how having a "local" stack for each block can be
> useful except for concurrancy?
Continuations in general.
Throwing out some ocaml examples, you can have "inner" functions which
survive the exiting of the "outer functions". For example, it's perfectly
OK to do (in Ocaml):
let foo x =
let f y = x + y in
f
Here you are returning an inner function which uses the context, the stack
frame, of the outer function. More complicated examples are possible.
The easiest way to handle this is to simply not allocate the stack frame
(the context) on the stack and free it when foo returns, but to instead
allocate it on the heap and allow the GC to collect it when it stops being
referenced.
Note that allocating data on the heap doesn't have to be expensive, given
generational copying garbage collection. Ocaml's common case to allocate
a block of heap memory is a mere five simple instructions long:
try_allocate:
movl young_pointer, %eax
subl $BLOCK_SIZE, %eax
cmpl %eax, young_limit
jb need_gc ; only taken if youngest generation is full
movl %eax, young_pointer
; %eax is now the pointer to our allocated object
...
need_gc:
; this can be out of line- it's unlikely we will end up here
call garbage_collector
jmp try_allocate ; try allocating again
For those who don't know x86 assembly, a C version similiar to the above
would be:
extern char * young_pointer;
extern char * young_limit;
static __inline__ void * allocate (size_t block_size) {
char * retval = young_pointer - block_size;
while (retval < young_limit) {
garbage_collector();
retval = young_pointer - block_size;
}
young_pointer = retval;
return (void *) retval;
}
Brian
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/sO0ANB/LIdGAA/ySSFAA/W4wwlB/TM
---------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
pragmatic_lang-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/