Bitwise logic gmpxx.h problems
Tim Van Holder
tim.vanholder at anubex.com
Wed Jul 30 17:06:30 CEST 2008
On 2008-07-29 13:48, Marc Glisse wrote:
>> The mpz->_mp_alloc field is "aware" of the allocation. Or what do you
>> mean?
>
> _mp_alloc is aware of what allocation size is requested from malloc. If
> malloc happens to allocate more (because I replaced the standard malloc
> by my own that allocates only even numbers of limbs), _mp_alloc does not
> know it. This means that replacing malloc/realloc/free is not such a nice
> way to specify an allocation policy.
Only in that it incurs unnecessary calls to the replacement realloc, really:
foo = mymalloc (5); // returns 500 bytes
foo = myrealloc (foo, 75); // simply returns foo again
foo = myrealloc (foo, 499); // ditto
foo = myrealloc (foo, 501); // first real underlying reallocation
myfree (foo);
gmp keeps track of when a "logical" realloc is needed; by default, each
"logical" realloc is also a "physical" realloc, but your custom version
can simply change that.
Of course, this means that for "real" customization, you pretty much
have to replace all 3 - but that's a given imho.
More information about the gmp-bugs
mailing list