Merge pull request #10327 from ritzdorf/patch-3

Differences in struct layout between memory and storage
This commit is contained in:
Đorđe Mijović 2020-11-19 14:41:09 +01:00 committed by GitHub
commit 5c92c2eb81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -1,3 +1,6 @@
.. index: calldata layout
*******************
Layout of Call Data
*******************

View File

@ -36,4 +36,37 @@ elements.
definitely zeroed out memory area, using such a pointer non-temporarily
without updating the free memory pointer can have unexpected results.
.. index: calldata layout
Differences to Layout in Storage
================================
As described above the layout in memory is different from the layout in
:ref:`storage<storage-inplace-encoding>`. Below there are some examples.
Example for Difference in Arrays
--------------------------------
The following array occupies 32 bytes (1 slot) in storage, but 128
bytes (4 items with 32 bytes each) in memory.
::
uint8[4] a;
Example for Difference in Struct Layout
---------------------------------------
The following struct occupies 96 bytes (3 slots of 32 bytes) in storage,
but 128 bytes (4 items with 32 bytes each) in memory.
::
struct S {
uint a;
uint b;
uint8 c;
uint8 d;
}