_mp_alloc vs ALLOC

bodrato at mail.dm.unipi.it bodrato at mail.dm.unipi.it
Fri Feb 24 11:41:10 CET 2012


Il Ven, 24 Febbraio 2012 11:32 am, Torbjorn Granlund ha scritto:
> bodrato at mail.dm.unipi.it writes:
>   I always used the MPZ_REALLOC macro, to enlarge (if needed) the memory
>   area available for an integer. This macro gives a (possibly new) pointer
>   with the requested size available... but it also copies the content.
>   Sometimes I know in advance that the content can be discarded. Is there
>   a standard way to ensure a given size without moving data?
> I use this trick for that:
>   rp = realloc (rp, 1);
>   rp = realloc (rp, newsize);

Inspired from mpz/mul.c... Maybe we can write a macro based on:

(*__gmp_free_func) (PTR(x), ALLOC (x) * BYTES_PER_MP_LIMB);
ALLOC (x) = newsize;
PTR(x) = (mp_ptr) (*__gmp_allocate_func) (newsize * BYTES_PER_MP_LIMB);




More information about the gmp-devel mailing list