From jan@swi.psy.uva.nl  Mon Feb 28 16:03:24 2000
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id QAA15091;
	Mon, 28 Feb 2000 16:03:24 +0100 (MET)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id QAA01771;
	Mon, 28 Feb 2000 16:03:37 +0100
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: Alfonso Ortega de la Puente <alfonso@ii.uam.es>,
        "Swi-prolog (Correo electrónico)" <prolog@swi.psy.uva.nl>
Subject: Re: About memory limits.
Date: Mon, 28 Feb 2000 15:45:45 +0100
X-Mailer: KMail [version 1.0.28]
Content-Type: text/plain
References: <01BF81FF.D5455E80@priamo.ii.uam.es>
In-Reply-To: <01BF81FF.D5455E80@priamo.ii.uam.es>
MIME-Version: 1.0
Message-Id: <00022816033703.32447@gollem>
Content-Transfer-Encoding: 8bit

[Please wrap your lines at about 70 characters].

On Mon, 28 Feb 2000, Alfonso Ortega de la Puente wrote:
>I am a swi-prolog  user on Windows 95 and 98.
>	I have to handle very long lists and strings. (over 2M)
>	I have tried the following:
>	(1)  To massively increase the available memory (-L128m -G128m
> -T64m ). The system fails trying to allocate virtual memory.

So you should go a bit lower (or use a machine with more space).  Most
likely Windows 95 already checks virtual memory on VirtualAlloc().

Anyhow, a list holding 2M small objects costs 24MB (16 on many other
Prolog's, but for SWI-Prolog a list is simply a ./2 term).  Small
objects are integers below max_tagged_integer (+/-16M on a 32-bit
machine), variables or atoms (though each different atoms costs heap
storage).  Large integers and floats cost more.

>	(2) To moderately increase the available memory (numerical
>values less than before) and to use files when the length of the
>strings or lists become big enough. I know that the program uses memory
>for a lot of tasks apart from lists and strings. Could anyone to
>suggest me a rational memory strategy?. For example,  is there a
>typical relationship between the size of memory used in lists and
>strings by a program and the system  limits of memory (trail, global,
>local, etc...)?

Lists live on the global stack.  The local stack holds stack frames
for prodecure calls as well as choice-points.  The trail holds undo
information.  Determinism is the key to keep memory usage low: far
less data on the local and basically none on the trail stack, while
much less of the global stack remains reachable.

Finally, if you actually have an array, SWI-Prolog allows you to use
a term with 2M arguments (costing 8M bytes to store, you can't assert
it).

Keep the debugger off while running code like this: in debug mode
it doesn't do last-call optimisation and is less eager destroying
choice-points.

When doing serious Prolog programming (i.e. when memory or peformance
becomes a point of consideration), read "The Craft of Prolog" by
Richard O'Keefe.

	Regards --- Jan

