I’m using a BigInteger as a set of flags in my audio thread. When using more than 128 bits the assignment operator always does a free then malloc even if the two BigInteger objects are the same size. Is there anything wrong with this suggested tweak:
BigInteger& BigInteger::operator= (const BigInteger& other)
{
if (this != &other)
{
highestBit = other.getHighestBit();
const size_t newAllocatedSize = (size_t) jmax ((size_t) numPreallocatedInts, sizeNeededToHold (highestBit));
if (newAllocatedSize <= numPreallocatedInts)
heapAllocation.free();
else if (allocatedSize != newAllocatedSize)
heapAllocation.malloc (newAllocatedSize);
allocatedSize = newAllocatedSize;
memcpy (getValues(), other.getValues(), sizeof (uint32) * allocatedSize);
negative = other.negative;
}
return *this;
}
fr810
October 9, 2016, 5:52pm
2
Yeah that looks pretty useful. Just to be sure though, you mean:
if (newAllocatedSize <= numPreallocatedInts)
heapAllocation.free();
else if (allocatedSize != newAllocatedSize)
heapAllocation.malloc (newAllocatedSize);
instead of what you wrote:
if (allocatedSize <= numPreallocatedInts)
heapAllocation.free();
else if (allocatedSize != newAllocatedSize)
heapAllocation.malloc (newAllocatedSize);
Right? Or am i missing something?
Of course, thanks for the catch. I’ve edited the original post.
fr810
October 9, 2016, 6:14pm
4
OK I’ve added this to the develop branch.
yfede
October 11, 2016, 11:02am
5
Has this change been unit-tested against possible regressions in RSAKey?
1 Like
One downside is that it may be faster, which is obviously a negative thing for this use case
fr810
October 12, 2016, 7:44am
7
Yes, I ran our RSA Key unit tests. I have a project where I have more involved unit tests for RSAKey and the unit tests passed.
1 Like
chkn
October 14, 2016, 9:02am
8
I get once in a while problems with the RSA classes now, are you 100% sure that there is no difference regarding this change?
EDIT:
Or maybe also because of the previous change?
IvanC
October 14, 2016, 9:21am
9
A few weeks ago a change in the BigInteger class has broken the RSA algorithms, but the issue has been solved now
chkn
October 14, 2016, 9:33am
10
Yes i know, thats why i am so skeptical, was it really solved, 100% ?
EDIT: I’m 95% sure this was an false-alarm, but i will keep an eye on that