Bitwise logic gmpxx.h problems

Marc Glisse marc.glisse at normalesup.org
Thu Jul 31 13:01:37 CEST 2008


On Wed, 30 Jul 2008, Tim Van Holder wrote:

>> _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.

I agree, I realized this later (when realloc doesn't move the memory it 
can be cheap and calling it is not an issue). By the way, default malloc 
implementations already work a bit like that.

-- 
Marc Glisse


More information about the gmp-bugs mailing list