- 可以理解為一個動態字節數組
- 支持以8bit或256bit寫入(MSTORE8, MSTORE)
- 但支持以256bit讀取(MLOAD)
- 0x00-0x3f (64bytes) => 用來存key的hash的值
- 0x40-0x5f (32bytes) => RAM大小,Free memory pointer
- 0x60-0x7f (32bytes) => 32bytes的0值插槽,用於需要零值的地方
uint
function testUint() public pure returns (uint){
uint a = 3;
return a;
}
String
function testShortString() public pure returns (string memory){
string memory x = "WTF";
return x;
}
x的長度3保存內存槽在0x80, 內容WTF保存在內存槽0xa0
Bytes
function testLongBytes() public pure returns (bytes memory){
bytes memory x = hex"365f5f375f5f365f73bebebebebebebebebebebebebebebebebebebebe5af43d5f5f3e5f3d91602a57fd5bf3";
return x;
}
x的長度為44(0x2c),保存在內存槽0x80
內容保存在內存槽0xa0-0xc0