Reduced number of allocated limbs after calling mpz_remove

Albin Ahlbäck albin.ahlback at gmail.com
Mon May 20 14:13:49 CEST 2024


Hejsan Niels,

> So not sure if code or docs should be adjusted ("usually not" rather
> than "never"). Do you think the "never reduce their allocated space"
> property is important for your usecase, or for other GMP applications
> general? If the strong statement is kept, this should perhaps be mention
> as another execption in mini-gmp/README.

In the project I help maintaining, we have started to rely on that mpz 
never reduce the number of limbs. This is to keep a minimum number of 
limbs allocated to 2, so that if one where to do a multiplication of two 
limbs, the result is guaranteed to fit inside the mpz without having to 
do a reallocation. Of course, the memory manager could check that 
recycled mpzs do have at least 2 limbs allocated, but that seems 
unnecessary since `mpz_remove` seems to be the exception.

Since this indeed seems to be the exception, I am fine with either 
documenting that this indeed is the exception (perhaps it should then be 
stated under the section "Memory management" as well as the docstring 
for `mpz_remove`), or fixing this in `mpz_remove`.

Best,
Albin


More information about the gmp-bugs mailing list