Link to this headingStorage
Types of Storage:
- Stack: Limited to 1024 items used for local variables
- Memory: Only valid during the transaction.
- Storage: Persistent and written to the blockchain.
Link to this headingMemory
Using the EVM MSTORE and MLOAD instructions you can save data to addresses into addresses. This is temporary and removed after the function call ends.
Usual Memory Layout:
| +-----------------+-----------------------------------------------------------+--------------------------------------+ | ||
0x00 – 0x3F | Scratch space (temp use) | Used for transient calculations |
0x40 | Free memory pointer (FMP) | Pointer to next free memory location |
0x60 | Solidity memory allocator scratch | Not guaranteed to be stable |
0x80+ | Actual dynamic memory (arrays, return data, ABI encoding) | You usually start writing from here |
Link to this headingTransient Storage
Using the EVM TLOAD and TSTORE instruction you can save data in between functions calls.
Link to this headingPersistent Storage
Using the EVM SSTORE and SLOAD instructions you can save data to addresses into addresses. This is stored in the contract slots and changes the blockchain state.