Strange behavior about BigInteger

the test code is here:


#include "../JuceLibraryCode/JuceHeader.h"
#include <iostream>

 

int main()
{
    using namespace std;
    MemoryBlock block1;
    block1.setSize(10 * 4,true);
    int* p = (int*)block1.getData();
    cout << "block1 is:" << endl;
    for(int i = 0; i <10 ; ++i) {
        p[i] = i+1;
        cout << p[i]<<" ";
    }
    cout << endl;
    BigInteger x;
    x.loadFromMemoryBlock(block1);
    MemoryBlock block2=x.toMemoryBlock();
    int* p2 = (int*)block2.getData();
    cout << "block2 is:" << endl;
    for(int i = 0; i < 10;++i) {
        cout << p2[i] << " ";
    }
    return 1;
}

 

I thought the output of block1 and block2 is same, but I get the result :

 

block1 is:

1 2 3 4 5 6 7 8 9 10

block2 is:

1 2 3 4 5 6 7 8 9 -33686262
 

so....why -33686262 here? I thought it would be "10".. THX

If you read the comment for that method, you'll see that it's designed to take bytes, not 4-byte integers. It'll also drop any leading zeros, so your assumption about the size of block that it returns is wrong - you're reading garbage beyond the end of block2.

Really not sure what you're trying to achieve, but it looks like a bad use of that class to me!