help with memory usage

Marc Glisse marc.glisse at normalesup.org
Tue Mar 10 21:38:26 CET 2009


On Tue, 10 Mar 2009, Christ Schlacta wrote:

>> I believe you should store the mpz_class directly, not a pointer to it (a
>> mpz_class is not much more than a pointer itself). It will save some amount
>> of overhead and simplify the code (no need for new/delete).
>
> I tried storing an mpz_class inside the prime_t class, and I
> experienced string corruption throughout the program.  when I switched
> to using a pointer and a new in the constructor, the problem went
> away.

That only means you didn't do it properly, not that it is a wrong 
approach.

>> You could also stop relying on the default memory allocator and either tell
>> gmp to use some other allocation function or allocate the buffers yourself
>> (for read-only never-deallocate numbers like your prime numbers seem to be
>> this should not be hard).
>>
> I have no clue how I would even do that :(

If all your numbers fit in say 4 limbs, you could try using 
mpz_array_init.

-- 
Marc Glisse


More information about the gmp-discuss mailing list