Small BigInteger feature request


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)
        else if (allocatedSize != newAllocatedSize)
            heapAllocation.malloc (newAllocatedSize);

        allocatedSize = newAllocatedSize;
        memcpy (getValues(), other.getValues(), sizeof (uint32) * allocatedSize);
        negative = other.negative;

    return *this;


Yeah that looks pretty useful. Just to be sure though, you mean:

    if (newAllocatedSize <= numPreallocatedInts);
    else if (allocatedSize != newAllocatedSize)
        heapAllocation.malloc (newAllocatedSize);

instead of what you wrote:

    if (allocatedSize <= numPreallocatedInts);
    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.


OK I’ve added this to the develop branch.


Has this change been unit-tested against possible regressions in RSAKey?


One downside is that it may be faster, which is obviously a negative thing for this use case :slight_smile:


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.


I get once in a while problems with the RSA classes now, are you 100% sure that there is no difference regarding this change?


Or maybe also because of the previous change?


A few weeks ago a change in the BigInteger class has broken the RSA algorithms, but the issue has been solved now


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 :wink: