Karim Belabas on Mon, 20 Aug 2018 18:14:05 +0200

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

Re: Using lazy vectors in library mode

* Jeroen Demeyer [2018-08-20 12:22]:
> Did you ever consider making it possible to automate dealing with this? For
> example, by storing this information in the prototype?

What would it improve ? The current situation is satisfactory on the GP side :
- no specific code is needed to handle garbage collection of these
objects, they are treated under the same general paradigm via GP variables;
- there are no memory leaks besides a few deprecated constructs
[ "inline" initializations ]. The latter can't be fixed without slowing
down the interpreter by adding further copies / destructors; so far,
it's a good compromise.

In libpari code, it's usually easy to explicitly call a destructor [ e.g.
obj_free ] any time a function such as 'ellinit' was used and we are
sure that we are now done with the object it produced. In a handful of
functions in the PARI library, it was indeed painful, for instance when
a lazy structure becomes recursive [ see e.g. ellanal_globalred ].

Writing such delicate code is hardly ever needed and in any case seems
extremely difficult to automate properly (without SEGVs) and efficiently
(without extra copies).

In something complicated like a Python interface, the tough problem is
not creating an object, but destroying it and ensuring that no pointer
to the destroyed components is ever dereferenced henceforth. You can always
call gunclone_deep() on an object you think may include leaked blocks
with a minor performance penalty.

The current situation is that the following functions create a lazy vector:

And many more functions include a lazy vector in their output:
(there may be more). We have no plan to add this to the description system.


Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite de Bordeaux         Fax: (+33) (0)5 40 00 21 23
351, cours de la Liberation    http://www.math.u-bordeaux.fr/~kbelabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux.fr/  [PARI/GP]