Karim Belabas on Tue, 04 Jul 2017 08:12:01 +0200

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

Re: gcopy_avma() is wasting stack memory compared to gcopy()

* Jens Schmidt [2017-07-04 07:47]:
> Hello PARI developer.
> PARI Library Guide (PDF) writes: "GEN gcopy_avma(GEN x, pari_sp *AVMA)
> return a copy of x as from gcopy, except that we pretend that initially
> avma is *AVMA, and that *AVMA is updated accordingly (so that the total
> size of x is the difference between the two successive values of *AVMA)."
> I noticed that gcopy_avma() needs more memory (~ 20%-30%) than gcopy()
> to create a copy of a GEN object if GEN is of non recursive type, e.g.
> t_POL or t_SER. Therefore I've written a shot test function to dissect
> the PARI stack.

The difference is due to gen_0: gcopy is allowed to keep (or create) pointers
to "universal objects", which need not be copied, whereas gcopy_avma is
a low-level function that was used to serialize objects out of a PARI
session and thus makes a deep copy of everything. It makes a huge
difference for sparse structures.

I am not sure a gcopy_avma with the above semantic [which has never been
documented] is useful anymore, it does not seem to be used in the PARI
sources any longer; it is present twice: in gclone (where it's
definitely not needed) and in the pthread interface (where I *believe*
at this point that it's not needed). I'll investigate.

The function used nowadays to serialize objects is copy_bin() [which
replaces a 0 t_INT by NULL, is as efficient as gcopy memory-wise]


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]