Memory allocation hints

David Warme David.Warme at GroupW.com
Thu Mar 6 03:55:56 UTC 2014


I am posting this to gmp-devel (instead of gmp-discuss) because it
concerns very arcane GMP implementation details.

GMP's trio (alloc, realloc, free) of memory allocation functions,
while simple, tends to rule out more sophisticated, fine-grained
memory heap optimizations.

For example, when no GMP function is active in the calling
context of any thread, all memory blocks held by GMP should
consist of simple "limb arrays" referenced by mpz_t, mpq_t, or
mpf_t objects.  The alloc/free usage pattern of such blocks are
likely to be quite unpredictable -- some will be very transient,
while others are long-lived and stable.

Blocks allocated within GMP, however -- particularly those
allocated using the TMP_DECL, TMP_MARK, and TMP_FREE mechanisms --
have predictably short lifetimes.  Using alloca() is of course a
good approach -- but when the block is too big for alloca(), one
might want to provide the "alloc" function with a hint that the
block will have a very transient lifetime.

The present GMP interfaces do not provide the ability to pass
such hints to the alloc / realloc functions.  Correcting this
would be a nice (although potentially incompatible) enhancement.



More information about the gmp-devel mailing list