Memory and storage in smart contracts
There are 6 places you can store data in Solidity:
- Memory
- Stack
- Storage
- Calldata
- Code
- Logs
Calldata and memory means that the data for function will only exist temporarly.
Other difference is that calldata cannot be modified — if you make variable = x in the code it will not compile.
Memory can be modified.
Storage can be modified but it’s permanent variable — memory and calldata are.
If you make a variable like below (outside) it goes thraig to being storage
What you have to remember is that stuct mapping and arrays need to have give the memory or calldata keyword
MAPPING
is a kind of dictonary where each key brings special set of data
mapping(string => uint256) public nameToFavoriteNumber; — with this code every single name (string) i going to map to a number (uinit256)