[gclist] Boehm's GC: marking collectable mem as uncollectable?

Stephan Rudlof Stephan.Rudlof@ipk.fhg.de
Wed, 08 Apr 1998 17:24:34 +0200


Is there any possibility to *later* mark collectable allocated memory as
uncollectable?

Problem: I'm working at a library and want to use GC for it. But I don't
want to force users of the library to work with GC. So I have to solve
the problem returning pointers to users as uncollectable. If all
functions in the library would return uncollectable pointers at default,
it would be a problem to call functions of the library internally from
other functions in it: Then I want to use GC!

Solution 1: An additional flag for each function, which says, if to
return collectable or uncollectable pointers.

Solution 2: Returning pointers as collectable as default, and supporting
a function 'makePtrUncollectable(void* ptr)'. Without having a function
of changing the status directly I had to allocate new mem as
uncollectable and copy in it.

Error handling: Solution 1 makes some problems using 'longjump' and
'setjump': If I'd alloc return pointers for users as uncollectable they
wouldn't be collected if some error with a longjmp would occur (possible
- but not nice - of course: freeing manually). Another variant would be
allocating always collectable pointers and copying or marking (see
above) at end of function from collectable to uncollectable mem. But
then I have to copy (worse) or at least to handle in every function what
is wanted.
Please excuse me, if there is a mistake in my 'Error handling' remarks:
It's the first time that I'm thinking of using setjump/longjump.

I prefer Solution 2: Collectable pointers as default and user *has* to
call a function, which transforms them in uncollectable pointers, if he
wants to store them in malloc'ed mem. Then I have some freedom dealing
with setjump/longjump and one parameter less for ordinary calls.


Any ideas or remarks to this problematic are welcome!

With best regards,
-- 
sr (Stephan Rudlof (srudlof@ipk.fhg.de))
   "Genius doesn't work on an assembly line basis.
    You can't simply say, 'Today I will be brilliant.'"
    -- Kirk, "The Ultimate Computer", stardate 4731.3