help with memory usage
aarcane at gmail.com
Tue Mar 10 23:16:03 CET 2009
On Tue, Mar 10, 2009 at 1: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
>>> 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
> That only means you didn't do it properly, not that it is a wrong approach.
for the record, I'm using C++ and libgmpxx, can you paste a snippett
that can handle mpz_class in a linked list container object without
>>> You could also stop relying on the default memory allocator and either
>>> gmp to use some other allocation function or allocate the buffers
>>> (for read-only never-deallocate numbers like your prime numbers seem to
>>> 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.
my largest number so far is 1339101911. I'm not sure if that would
fit in 4 limbs, but I'm sure I can read the documentation and find
out. my major concern is how would this scale as the numbers get
larger as the program runs, it generates new numbers to add to the end
of the list.
on an aside, I wrote a new version that doesn't rely on storing the
whole list in memory, but because it's simpler, it's disk bound :(
I'll have to write a third version later.
> Marc Glisse
(\_/) This is Bunny. Copy and paste Bunny
(='.'=) into your signature to help him gain
(")_(") world domination.
More information about the gmp-discuss