I'm curious what happens if you try to do the next thing:
contract C {
Struct S {
uint a;
uint b;
}
mapping(address => s) structs;
function updateStructs(S sInstance) private {
structs[msg.sender] = sInstance;
}
function addStruct (uint _a, uint _b) payable {
S memory s = S({a: _a, b: _b});
updateStructs(s);
}
}
As I understood how variables work, the addStruct creates memory variable that has only function scope and will be deallocated once this transaction/message is processed. So what will remain in structs[msg.sender]
after addStruct has been called? Will changing updateStructs(S sInstance)
to updateStructs(S storage sInstance)
change something?
s
is not deallocated untiladdStruct
returns. It might be helpful to understand stack frames, or activation records – libertylocked Nov 13 '17 at 4:04