From c68efc6e038df832f0ef9d3c391614f448917b29 Mon Sep 17 00:00:00 2001 From: ritzdorf <10403309+ritzdorf@users.noreply.github.com> Date: Thu, 19 Nov 2020 11:29:20 +0100 Subject: [PATCH] Differences in layout between memory and storage - More explicit description with two examples - Moved index pointer to correct file --- docs/internals/layout_in_calldata.rst | 3 +++ docs/internals/layout_in_memory.rst | 35 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/docs/internals/layout_in_calldata.rst b/docs/internals/layout_in_calldata.rst index cfabaf99f..aef27b153 100644 --- a/docs/internals/layout_in_calldata.rst +++ b/docs/internals/layout_in_calldata.rst @@ -1,3 +1,6 @@ + +.. index: calldata layout + ******************* Layout of Call Data ******************* diff --git a/docs/internals/layout_in_memory.rst b/docs/internals/layout_in_memory.rst index 34c3035eb..bad8c1654 100644 --- a/docs/internals/layout_in_memory.rst +++ b/docs/internals/layout_in_memory.rst @@ -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 \ No newline at end of file + +Differences to Layout in Storage +================================ + +As described above the layout in memory is different from the layout in +:ref:`storage`. 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; + }