Next: , Previous: , Up: MPRIA Basics   [Index]


4.7 Memory Management

Basically MPRIA mimics and relays to the GNU MP memory management, except notably for temporary use (see Memory Management in The GNU MP Manual).

The mpq_t type is for the implementation of the mpri_t type what the mpz_t type is for the implementation of the mpq_t type itself: mpri_t variables never reduce their allocated space, as mpq_t variables.

All memory is allocated, reallocated and freed by passing on to the GNU MP memory functions as grabbed from mp_get_memory_functions (see Custom Allocation in The GNU MP Manual).

While GMP uses temporary memory on the stack (via alloca), MPRIA creates, passes along and intensively reuses workspaces for internal computation; the various created workspaces are freed before exiting with the help of the standard C atexit function (see Cleanups on Exit in The GNU C Library Reference Manual), therefore no memory leaks should be reported by tools like valgrind (http://valgrind.org/).

Teething Note: At the time of writing, this internal workspace machinery is robust but global, read not yet thread safe, and no high-level function is yet implemented to free the created workspaces, or part of them, from time to time.