Last active
February 16, 2018 17:22
-
-
Save DaveAppleton/c13257ba5b68e04b4cfdbce501c9293e to your computer and use it in GitHub Desktop.
Memory vs Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.19; | |
contract TestStorage { | |
struct St { | |
uint256 amountPaid; | |
uint256 amountOut; | |
bool registered; | |
} | |
mapping(address => St) store; | |
function addMemFunds() public payable { | |
St memory myStuff = store[msg.sender]; | |
myStuff.amountPaid += msg.value; // and the other members | |
store[msg.sender] = myStuff; | |
} | |
function addMemFail() public payable { | |
St memory myStuff = store[msg.sender]; | |
myStuff.amountPaid += msg.value; // and the other members | |
} | |
function addStorFunds() public payable { | |
St storage myStuff = store[msg.sender]; | |
myStuff.amountPaid += msg.value; | |
} | |
function mine() public view returns (uint256 toPay, uint256 paid) { | |
St memory thisSt = store[msg.sender]; | |
toPay = thisSt.amountPaid; | |
paid = thisSt.amountOut; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment