__gmp_allocate_func and garbage collection

Marc Glisse marc.glisse at normalesup.org
Tue May 5 06:53:45 CEST 2009


Hello,

some garbage collectors (take the one by Boehm-Demers-Weiser) provide 2 
malloc variants, one for pure "data", and one for stuff that may include 
pointers to garbage collected memory (the GC 0-initializes memory in 
this case).

On some private mailing list, someone asked about using a garbage 
collector with gmp. I was thus wondering whether it was safe to use
mp_set_memory_functions with the first ("pure data") variant of malloc, or 
whether we had to use the safe general variant.

Scanning through the GMP sources, and excluding tune/, tests/ and 
tal-debug, I found only one problematic file (I may have missed others, 
obviously). In randlc2x.c, __gmp_allocate_func is used to allocate a 
structure that contains several mpz_t.

So it looks like if you don't use random numbers, it is safe to use the 
fast allocation routine. It would be nice to have some more formal 
guarantees though. I understand this message would be more convincing with 
benchmarks, but now is not the best time, I just wanted to get the idea 
out before I forgot.

-- 
Marc Glisse


More information about the gmp-discuss mailing list