Internal Memory allocation?

Simon Hafner simon.hafner at
Thu Jul 2 10:24:40 UTC 2020

On Tue, Jun 30, 2020 at 8:45 PM Marc Glisse <marc.glisse at> wrote:
> On Tue, 30 Jun 2020, Simon Hafner wrote:
> > I'm interested in the internal memory allocation of a few mpn functions, namely
> >
> > c_mpn_add, c_mpn_sub, c_mpn_mul, c_mpn_tdiv_qr, c_mpn_divrem_1, c_mpn_mod_1
> >
> > Do any of these functions allocate additional memory which is not seen
> > by the structures passed in? According to a small grep, I can't see
> > any, but I'm not well-versed in asm/C.
> I strongly doubt that add/sub would allocate, but for the rest:
> $ grep -i alloc mpn/generic/mul.c
> ... 8 allocations ...
> and that's without counting the functions from other files that are
> called.

Aye, I wasn't looking in the right place. Thanks for the help.

To clarify, according to the manual [1]

> A destination operand is specified by just a pointer. It is the responsibility of the caller to ensure that the destination has enough space for storing the result.

Can I assume it to be true that all space allocated by the functions
is internal use only, and freed afterwards?


More information about the gmp-discuss mailing list