pragma solidity ^0.4.24;
contract FreeMemory2 {
struct Increase {
uint dist;
uint src;
}
function callFuncMemoryCheck(uint a, bool _memoryUse) public pure returns(uint) {
uint res = a;
Increase memory increase;
increase.src = a;
for(uint i=0; i<a; i++) {
if(_memoryUse) {
increase = doExec(increase);
} else {
res = addFunc(res, 5);
}
}
assembly {
res := mload(0x40)
}
return res;
}
function addFunc(uint a, uint b) internal pure returns(uint) {
return a + b;
}
function doExec(Increase memory inc) internal pure returns(Increase memory) {
inc.dist += inc.src;
return inc;
}
}