1
contract Foo {

    struct Bar {
        address owner;
        uint[] x;
    }
    mapping( uint => Bar) bars;

    function foobar(uint index) public {
        Bar memory b = bars[index];
        b.owner = msg.sender;
        b.x = new uint[](0);  // will that be a dynamic array in storage?
  
    }

}

How efficient is these? ☹️☹️☹️

1
b.x = new uint[](0);  // will that be a dynamic array in storage?

As for now it's not. It's an array of length 0.

It could be dynamic but you will still need to know the length of the array on creation. The (0) represent the length of this array. Therefor you should probably use something like;

b.x = new uint[](incomingArray.length);

so this array will be the length of what ever array you pass to it.

1
  • Thank you for the idea... Great response.
    – Abbracx
    Sep 28 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.