Creating array of structures

midhun0003midhun0003 Member Posts: 15
Can i create an array of structures of size 1000000 ? Any other way to create structures dynamically without changing gas values?

Comments

  • chrisethchriseth Member Posts: 170 ✭✭✭
    edited November 2015
    I assume that you want to create that array in storage, then it is free (correction: it is not totally free, but the cost does not depend on the size). It is not free to fill it with non-zero values, though.
    Creating arrays in memory is not yet implemented.
  • midhun0003midhun0003 Member Posts: 15
    contract Test{
    struct coinWallet {

    bytes name;
    bytes address;
    address accountaddress;


    }


    coinWallet[] public myWallet;
    function Test(){


    for(uint i=0;i<1000000;i++){
    myWallet.push(coinWallet('1','1',0x8));

    }

    }
    }


    When i run this program its showing that "its deployed but not seems to be working try adjusting gas limit and gas values".Even if i adjust those values it cannot initialize 1000000 of datas
  • chrisethchriseth Member Posts: 170 ✭✭✭
    The constructor is just too expensive and will not fit the block gas limit.
    As you are initialising all coin wallets in exactly the same way, you can change your logic to
    handle uninitialised values (zero) as your default values and not store anything. This way, it will work.
  • midhun0003midhun0003 Member Posts: 15
    If i am not initializing any values then i cannot update the values of variables from a function.
Sign In or Register to comment.