Replacement for GMP

Esa Ilari Vuokko eivuokko at
Wed Aug 2 17:45:34 EDT 2006

On 8/3/06, John Meacham <john at> wrote:
> On Wed, Aug 02, 2006 at 03:22:57PM -0400, Peter Tanski wrote:
> > Esa and I had discussed the possibility of copying the value returned
> > from the Bignum lib into the GHC system, which certainly would not be
> > very memory efficient, but might be faster.  Among other memory
> > modifications, it might be a good idea to initialise the Bignum lib
> > with the RTS and modify the lib with a memory cache or garbage
> > collection system of its own.
> I don't understand why this would be useful. Just use the standard FFI
> ForeignPtr mechanism and it takes care of garbage collection for you and
> doesn't have any issues with concurrency. This would also make the
> library fully portable to any haskell implementation with FFI support.

There is atleast one imaginable situation where copying would be
safer:  Imagine using a library that changes GMP memory allocation
routines on (user-called) initialisation.  Integers allocated before
library init would probably crash the system when their finalisers
were giving free-calls bad addresses.

Then there's minor optimisations - memory being only in
haskell heap it can be compacted, no need to check or run
finalisers.  Whetever these give more than we lose...benchmarking
is hard without competiting implementations.

I am not arguing it's a good choice.  But it is totally valid choice with
some good points, and it is interesting idea.  There's also more a
possible drawback: It requires even more knowledge, or assurances,
from inner workings of the library.

Best regards,

More information about the Glasgow-haskell-users mailing list