Bill Allombert on Fri, 20 Feb 2004 00:16:54 +0100

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

Re: patch for a `soft stack limit'

Hello PARI-dev,

Here a new patch that make gp to invalidate the stack
by freeing it and reallocate it after a computation
is done. On system implementing copy-on-write memory management like Linux,
this mark the satck as allocated-but-not-used memory that does not take
system resource.

The patch is very simple and portable, but could stress some malloc()
implementations on older system.

This patch is probably more usefull together with the previous one,
but can be used standalone.

(if you applied the previous one, you need to change top-bot by

Note: I added a test av==top since allocatemoremem will destroy
anything between top and av. In practice, av==top is true.
I am not sure why.

Index: src/gp/gp.c
RCS file: /home/cvs/pari/src/gp/gp.c,v
retrieving revision 1.218
diff -u -r1.218 gp.c
--- src/gp/gp.c	20 Jan 2004 19:20:32 -0000	1.218
+++ src/gp/gp.c	19 Feb 2004 18:15:22 -0000
@@ -2722,6 +2722,7 @@
         char *s = (char*)global_err_data;
         if (s && *s) outerr(lisseq(s));
 	avma = av = top;
+        allocatemoremem(top-bot);
         prune_history(H, tloc);
         GP_DATA->fmt->prettyp = outtyp;
@@ -2758,6 +2759,7 @@
     if (GP_DATA->flags & SIMPLIFY) z = simplify_i(z);
     z = set_hist_entry(H, z);
     if (!gpsilent) gp_output(z, GP_DATA);
+    if ( av==top ) allocatemoremem(top-bot);