Karim BELABAS on Sat, 18 Jan 2003 17:23:10 +0100 (MET)


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

Re: how to free pari's memory


On Thu, 16 Jan 2003, Ramón Casero Cañas wrote:
> I initialize and use a PARI 2.1.4 stack in a function of a C++ program. I
> thought that after returning from the function, the stack and pari data would
> be freed.

How so ? _If_ PARI had been written in C++ (which it isn't), some default
destructors would be called for declared objets when leaving scope, but
there's no way this could undo all the initializations [ would prevent the
library itself from functionning properly ! ]

Anyway, if you want to use PARI, then remove it completely [ not a good idea
if you do this more than once : it involves a very significant overhead ],
you have to do it by hand:

  void freeall(void);
  void pari_sig_init(void (*f)(int));

  freeall();
  if (INIT_SIG) pari_sig_init(SIG_DFL);

None of the above is documented (it's the first time the problem of unloading
the library is raised...)

> But I have noticed that if I press CTRL-C while the program is
> running (after returning from the function), I get a
>
>   ***   user interrupt.
>   ***   Error in the PARI system. End of program.
>
> Is there a way to delete the stack. I suposse this is not a garbage
> collection.

Not related to stack. PARI traps a number of signals for its own use, and you
want to restore default behaviour. Either use SIG_DFL as above, or
re-initialize your own signal handler [ no way to recover the one PARI
replaced using PARI functions, I'm afraid ]

Good luck,


    Karim.
-- 
Karim Belabas                    Tel: (+33) (0)1 69 15 57 48
Dép. de Mathématiques, Bât. 425  Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud             Email: Karim.Belabas@math.u-psud.fr
F-91405 Orsay (France)           http://www.math.u-psud.fr/~belabas/
--
PARI/GP Home Page: http://www.parigp-home.de/