pragma solidity 0.4.24;
contract Test {
struct Book {
uint id;
}
Book[] books;
uint public status;
constructor() public {
books.push(Book(10));
}
function changeStatus1() external {
Book storage book = books[0];
if (book.id == 10) {
status = 1;
}
}
function changeStatus2() external {
Book memory book = books[0];
if (book.id == 10) {
status = 2;
}
}
}
It seems like the method that uses storage
costs less gas (26982 vs 27063). What is the best practice when just reading the value (and maybe using it in an if
statement). Should I use storage
or memory
?