3

Started to learn OPCODEs and the term free memory pointer as well as offset are frequently mentioned. What do they mean?

2 Answers 2

4

The free memory pointer is a pointer (i.e. shows where to go) to the next available slot of memory. Meaning that if you need to create a new uint256 for exemple, the free memory pointer will let the EVM know where to create the new uint256. Then since that spot is now occupied by your newly created uint256, the free memory pointer will be updated to a new, unoccupied memory slot. Read more here.

Offset is just the number of bytes to offset the current reading target. So if my pointer points here

   v
0x010203040506070809101a1b1c1d1e1f

pointing to the first byte, i can offset it of, let's say 5, and my memory pointer will be there:

             v
0x010203040506070809101a1b1c1d1e1f

Hope this helps!

0
0

Understanding using a simple analogy:

EVM has a volatile storage called memory. You can store bytes of data in memory. Think of memory as a long queue of bytes. Like so:

xxxxxxxxxxxx*

The free memory pointer(*) keeps track of where the queue ends, so new data can be placed. More specifically, the free memory pointer stores what is the first free slot available at the end of the queue. Once new data comes in, the free memory pointer is updated to reflect the first free slot at the end of the queue.

Offset of a byte is number of bytes ahead of it.

cO ff ee 40*
--|--|--|-- 
 1  2  3  

So the offset of the byte 40 is 3 bytes since there are 3 bytes ahead of it in the queue!

PS: We are representing bytes in hexadecimal, so 2 hex characters are one byte

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.