steve@watchfield.com ("Stephen F. K. Leach") writes:
> Date: 10 May 1999 13:26:44 GMT
> Organization: cs.bham.ac.uk MAIL->NEWS gateway
>
> Hi Robert,
>
> I do not think that there is any general means of coercing the GC into
> releasing store. There are a couple of specialised procedures
> sys_grbg_list and sys_grgb_destpair that do this for lists.
A possible use for this might be in connection with a question
Mark Roberts asked recently: how to use the Pop-11 syssort library
procedure, which sorts lists, in order to sort other things, e.g.
arrays.
The solution I suggested was to use datalist to get the contents of
the structure, then sort using syssort in non-copying mode, then
transfer the resulting list elements back to the structure.
The list created by datalist can then safely be given to
sys_grbg_list:
define general_sort(structure, predicate);
;;; get a list of the elements of structure
lvars temp_list = datalist(structure);
;;; Sort, using the given predicate and use fill to restore
;;; the items in sorted order, ignoring the result of fill.
explode(syssort(temp_list, false, predicate)), fill(structure) ->;
;;; return the list cells to the memory manager
sys_grbg_list(temp_list);
enddefine;
vars nnn = newarray([5 15], identfn);
explode(nnn) =>
** 5 6 7 8 9 10 11 12 13 14 15
;;; now reverse the array
general_sort(nnn, nonop > );
explode(nnn) =>
** 15 14 13 12 11 10 9 8 7 6 5
> However, it is important to realise that manual deallocation of store
> jeopardises the integrity of the run-time system.
Though probably not in contexts like the above where it is obvious
that nothing can use the links of temporary list, as the predicate
is applied only to the elements of the list.
However, I agree that being sure in general is difficult, and
impossible in some cases.
> So - at the risk of telling grannies not to suck eggs - do not bother
> with it.
It's worth mentioning that there are all sorts of ways you can
reduce the frequency of garbage collections by taking a little care.
Some are described in HELP EFFICIENCY, e.g. avoid adding items to
the "right hand" end of a list in a loop, like this:
[^^list ^item] -> list;
or, equivalently:
list <> [^item] -> list;
I.e. build lists up from the left not the right. You can always
reverse the list at the end of the loop. (Or better still build the
list on the stack by using [% .... loop instruction .... %]
> This is NOT the same situation for incremental garbage collectors, such
> as Java's, incidentally.
A long time ago we considered adding an incremental garbage
collector to Poplog and decided that the cost, namely a predictable
overall halving of speed of access to datastructures was not worth
the marginal gain in avoiding occasional total stoppages, especially
as the Poplog garbage collector is so fast. (I hardly ever notice a
garbage collection while working with the editor Ved on a Sun
workstation, even though the editor continually generates garbage.)
Aaron
===
--
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs/ )
School of Computer Science, The University of Birmingham, B15 2TT, UK
EMAIL A.Sloman AT cs.bham.ac.uk (NB: Anti Spam address)
PAPERS: ftp://ftp.cs.bham.ac.uk/pub/groups/cog_affect/0-INDEX.html
|