With for example
struct Foo {
mapping(address => uint) b;
}
Foo[] foo;
if a function only deals with foo[4], can it reference it from storage without copying it? is that what
function c() {
Foo memory p = foo[4];
}
does?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityWith for example
struct Foo {
mapping(address => uint) b;
}
Foo[] foo;
if a function only deals with foo[4], can it reference it from storage without copying it? is that what
function c() {
Foo memory p = foo[4];
}
does?
To get a reference from a variable in the contract state you have to use storage
qualifier
function c() {
Foo storage p = foo[4];
}
Inside the c
function all changes to p
will update foo
also.
memory
, does it copy anything, or, is it a reference except it cannot be updated?
– cotld
Nov 6 '18 at 6:23
storage
? is storage
cheaper in gas as well?
– cotld
Nov 6 '18 at 6:56