help with memory usage

David Gillies daggillies at gmail.com
Tue Mar 10 22:58:42 CET 2009


if you're using C++, why not use a std::list<mpz_class>?

#include <list>
#include <fstream>
using namespace std;

mpz_class tmp
list<mpz_class> plist;
ifstream pfile("...");

while(!pfile.eof())
{
pfile >> tmp;
plist.push_back(tmp);
}

On Tue, Mar 10, 2009 at 2:38 PM, Marc Glisse <marc.glisse at normalesup.org> wrote:
> 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
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at gmplib.org
> https://gmplib.org/mailman/listinfo/gmp-discuss
>



-- 
David Gillies
San Jose
Costa Rica


More information about the gmp-discuss mailing list