Help I am a beginner

Hi,

I was going through blockchain 101, though I don’t understand why he puts memory next to certain variables. Could you explain this to me thanks.

1 Like

hey @Darius311, hope you are well.

The Ethereum Virtual Machine has three areas where it can store items.

The first is “storage”, where all the contract state variables reside. Every contract has its own storage and it is persistent between function calls and quite expensive to use.

The second is “memory”, this is used to hold temporary values. It is erased between (external) function calls and is cheaper to use.

The third one is the stack, which is used to hold small local variables. It is almost free to use, but can only hold a limited amount of values.

For almost all types, you cannot specify where they should be stored, because they are copied everytime they are used.

The types where the so-called storage location is important are structs and arrays. If you e.g. pass such variables in function calls, their data is not copied if it can stay in memory or stay in storage. This means that you can modify their content in the called function and these modifications will still be visible in the caller.

Carlos Z

Hi Carlos,

Thanks for the response I though no one would probably read this lol. What do you mean by cheaper and expensive to use. When you refer to “memory” are you talking about the computer cache or is it stored somewhere else?

In terms of gas fees, using storage will manipulate the blockchain (smart contract storages like a mapping or an array), so its expensive to use.

While memory do not made a direct change on the blockchain, so its cheaper since their values are holded by the evm for few moments (while function is executing), once the executiion ends, the values stored on a memory variable is deleted.

Carlos Z

Ok thanks Carlos.

I had another question for structs. On line 10 does he create an array by declaring Person[ ]. And what does “people” mean besides it?

It means to create an array [] based on Person struct, which its called people, this array will storage on each of his index, values based on the struct.

Carlos Z

Got it thanks, for helping really appreciate it.