On Nov 29, 7:35 am, terminator
> On Nov 27, 11:05 pm, mike3
> I did not mean the global buffer to be placed on heap;I mean that when
> you store the value in the result 'bignum' a dynamic allocation
> happens and it is better to have a none static vector buffer ( whose
> implementation performs the dynamic allocation ) and swap it to the
> result (that prevents a second dynamic allocation).
>
Why does a dynamic allocation happen to the bignum?
In the floating point routines, the multiplication
stores it's wide result in a temporary buffer that's been
preallocated to the full size. Then the _upper part_ of
this buffer (it's most-significant digits) is copied to
the destination floating point number, so that it fits
within the allotted precision. Floating point numbers
are intended to be static, their precision does not
change except with specifically-made resize functions,
for maximum performance.
>
>
> > If you have set up to use X amount of precision, your
> > global array needs only hold 2X worth.
>
> actually a mutiplication holds **less than** or equal to
> length1+length2.
Yes, that's right.
> if you want to store just necessary digits then a normal array buffer
> can help decrease the size of resulting vector , but there are better
> programing techniques to avoid a normal array while achiving similar
> performance.
>
But then you need to count digits to figure out how
big the product is going to be.
The big problem here is handling the allocation/
deallocation of the memory.
> > There may be another
> > array that holds X+1 or X+2's worth for computing
> > transcendental functions hence the multipliaction
> > buffer may need to hold 2X+2 or 2X+4's worth. But that is
> > not a problem. One need only resize it if the precision
> > being used is too small. Then when it's resized, it stays
> > that big. (It cannot grow indefinitely though as the
> > bignum package contains a max precision limit coded in.)
> > And the memory consumption is not too great -- these
> > numbers can take up at most 1 Kbyte or so, so that's only
> > a few Kbytes of storage which is nothing on today's PCs.
>
> suppose a number of 'length1 ' multiplied by another of 'length2' then
> you just need to check whether 'length1+length2' is greater than the
> 'maximum_size' .
> 'length1+lenght2' is less than '2*max(length1,length2)'.And none of
> the operands need be less than 'maximum_size/2' but as mention
> formerly ,the sum of lengthes must be not greater than 'maximum_size'.
>
But where is this temporary buffer stored? Also,
in my multithreaded application, how can you give
each thread it's own buffer without having to
pass special parameters to every bignum routine
(impossible with overloaded operators!), _and_
not having a "rationing" method where the threads
take turns using a single buffer, which utterly
destroys the parallelism that would be gained
on machines with multiprocessing ability
(multiple CPUs/multiple cores)?