mp_set_memory_functions

delta trinity deltatrinity@hotmail.com
Mon, 03 Mar 2003 23:35:23 -0500


>Hi, I am trying to create custom allocation functions as follows
>
>  mp_set_memory_functions(myAlloc, myRealloc, myFree);
>
>Where myAlloc, myRealloc, and myFree are just wrappers of malloc, realloc, 
>and free (for testing purpose)
>
>I then try a simple example to see if it works
>
>mpz_t n;
>
>mpz_init(n);
>
>mpz_ui_pow_ui(n, 10, 108);
>
>I run the code in a debugger. What surprises me is that the code never 
>stops in myAlloc. How could this happen? The document states that the 
>custom functions will be used for all memory allocation done by GMP. Does 
>anyone know why?
>
>Thanks,
>
>Minh

This may sound obvious but how did you debug?  Did you put breakpoints 
inside your memory wrapper functions?  Just single-steping through the main 
functions (i.e. mpz_init, mpz_ui_pow_ui, ...) may not be enough if you don't 
specifically put breakpoints inside the memory functions.  This is because 
when you call mpz_init, the debugger see that you're execuing code outside 
of the program lists of source codes and doesn't know that the memory 
functions will be called (actually, called-backed).  So, leaving the scope 
of the source code, the debugger just execute a 'step-over'.

So, whenever you specify callbacks functions, you should specifically put 
breakpoints on those callbacks if you want to step through them.

Alternatively, just to be sure, you could write a printf inside the memory 
functions, just as a quick debug to see if they get invoked.

Eric.

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail