memory

Peter Schachte pets at students.cs.mu.OZ.AU
Wed Feb 4 15:00:52 AEDT 1998


I'd like to commit a new extras subdirectory, but that change needs a new
memory zone which I'm calling the global heap.  The idea of this zone is
that it's like the heap, but memory isn't reclaimed on failure.  The trouble
is that the code for creating a new heap zone isn't documented, and so
probably shouldn't be used in an extras package.  Fergus suggested moving
the code to allocate this zone into the runtime system, but this leaves the
question of what the interface should look like.  Here's my proposal:


	Word MR_make_permanent(Word term, Word type_info);

	Returns a copy of term that can safely be stored in C's memory
	somewhere even if it may be accessed after failure.  Of
	course, type_info is a type info structure for term.


	Word MR_make_partially_permanent(Word term, Word type_info, 
					 Word *limit);

	This is the same as MR_make_permanent, except that if limit is an
	address on the heap, parts of term that are "older" than limit will
	not be copied.  This is useful when you know that the permanent copy
	of term will not be accessed after the heap pointer has backtracked
	beyond limit.  Naturally, this always occurs when the permanent term
	is to be stored in *limit.

	I'd like to describe the limit argument without referring to the
	"heap," but don't see how to.

I believe these two functions, as part of the documented standard Mercury
runtime, should be enough.  In conservative GC grades, these functions just
return term, otherwise they allocate the "global heap" zone if it hasn't
already been allocated, and copy term there, returning a pointer.  The
resulting pointer could be used as if it were an ordinary heap term.  Of
course, the global heap is never reclaimed so garbage collection is pretty
important, but I'll leave that for Tyson to worry about.  What else is there
to say?  I guess the size of the global heap zone should be handled like the
solutions heap zone. 

Comments?  Have I missed something?


-Peter Schachte			| There is something fascinating about
pets at cs.mu.OZ.AU		| science. One gets such wholesale returns of
http://www.cs.mu.oz.au/~pets/	| conjecture out of such a trifling investment
PGP key available on request	| of fact. -- Mark Twain





More information about the developers mailing list