T
terminator
mike3 said:<snip>I just finished testing another attempt at this. It seems the
problem is not the choice of vector vs array, but instead how
the memory is handled.A temporary array made like this:Digit *digits(new Digit[4]);and then removed using delete is just as slow as a vector.Whereas an array like this:Digit digits[4];is far faster.
Welcome to the dark side of the dynamic memory management.
The problem is though those variable-length arrays are
necessary -- no easy ways around 'em with the Floating Point
(FP) routines as I need to store bitshifted versions of the
operands without munging said operands. It might be possible
to allocate arrays of the second type I discussed above, but
then all the digit-manipulators have to take arrays not
vectors and that just doesn't seem like a good idea. Now,
if my program were single-threaded, I would have been able to
make do with a global buffer that would only get allocated once,
and always use that. But the program is going to be multi-
threaded, so having a single global buffer cannot really work.
And it seems ugly to have to pass a buffer operand to every
single arithmetic routine and is downright impossible when
using overloaded operators.What do you do?
There are commercial and homegrown memory managers that can be
made much faster than the generic one your RTL supplies.
Great idea.
Also
consider that if you know the possible largest size of your
array, use that to define an automatic array, even if you only
use part of it in the current call to your function.
consider:
a=b*c;
'a' would need to be dynamically allocated in the end.
Dynamic allocation is generally inevitable in programs using that
'bignum'; so why to dirty the stack for preventing what has to happen?
regards,
FM.