Struct Reference type size?🤔

struct Monster {
        uint248 exp; 
        uint8[] bodyPart;

Does Monster struct occupy 1 or 2 uint256 in packing?
What is the size of uint8[ ] occupation in Struct type

1 Like

Since bodyPart is a dynamic array, its layout in memory begins with the (256-bit) length of the array, so this structure definitely occupies more than 1 slot.

Note that you haven't shown whether or not this structure is being used in storage to begin with, and that's where the number of slots actually matters.

Thank you your response but I didn't really understand.

If I have two scenarios initialization and assign a new value to uint8[] after initialization...
how many bytes the two scenarios actually will be used? :sweat_smile:

  1. Your question is not entirely clear. If you have a specific piece of code that it refers to, then I suggest that you add it as part of your question.
  2. I explained that even before assigning a value to the dynamic array, your structure already occupies more than a single slot, because 248 + 256 (the length of the array) > 1 slot.
  3. Also as I explained, the whole "slot analysis" becomes critical only when your data is in storage (i.e., global variables). Is that indeed the case? It appears that your question lacks some relevant coding details in order to determine this issue.