users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: garbage collection


From: Mike Maxwell
Subject: Re: garbage collection
Date: Tue, 17 Feb 2004 11:01:07 -0500

Gregory Bourassa wrote:
> Prolog is generally stack-oriented, so a garbage collecter
> usually makes sense only for the global heap area, if any.

Thanks for the comments--I looked up "heap" in the index of The Craft of
Prolog.  There are two references, one of which (p 148) doesn't seem to
pertain, and for the other of which (p 74) I can't seem to find the word on
the page.  Must need new reading glasses...  So I'm unclear under what
circumstances you use the heap, although I gather it's used for compound
terms.

> Interestingly, your reference to "rather trivial code to read in
> words from the input" reminds me that string I/O goes on the global
> heap in Visual Prolog -- and there is stays until you backtrack past
> the I/O call.    Gnu Prolog may have a similar behaviour; I don't
> know for sure.  You need to be particularly careful of I/O code where
> garbage is concerned.

As for I/O, I'll actually be ripping out the original and replacing it with
my own code.  As it happens, the input to the parser comes tokenized, with
one word per line.  So I'm thinking of something like the following (not
tested yet):

run :-
    repeat,
    readline(Wordform),
    process(Wordform),
    fail.

process(eof) :-
    halt.
process(Wordform) :-
    parse(Wordform, Parses),
    display(Parses).

If I'm understanding you correctly, it looks like it will backtrack past the
readline every time it finishes a word, so the heap should be reclaimed at
that point, correct?

    Mike Maxwell
    LDC
    address@hidden





reply via email to

[Prev in Thread] Current Thread [Next in Thread]