I read a Note in documentation of Solidity:
The type
bytes1[]
is an array of bytes, but due to padding rules, it wastes 31 bytes of space for each element (except in storage). It is better to use thebytes
type instead.
I know that elements in memory always occupy multiples of 32 bytes, so each element of bytes1[]
wastes 31 bytes. On the other hand, the bytes
type is similar to bytes1[]
, but it is packed tightly in calldata and memory. Therefore, bytes
in memory can store data in the same way as it does in storage? Can somebody explain more details about the difference between bytes
and bytes1[]
?