Update note about calldata

This commit is contained in:
t11s 2021-07-18 10:10:07 -07:00 committed by GitHub
parent bb040e40ed
commit 61e4c29cf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,19 +28,18 @@ annotation, the "data location", about where it is stored. There are three data
``memory``, ``storage`` and ``calldata``. Calldata is a non-modifiable, ``memory``, ``storage`` and ``calldata``. Calldata is a non-modifiable,
non-persistent area where function arguments are stored, and behaves mostly like memory. non-persistent area where function arguments are stored, and behaves mostly like memory.
Calldata is usually preferred over memory for external functions but is not required after version 0.6.9. .. note::
If you can, try to use ``calldata`` as data location because it will avoid copies and
also makes sure that the data cannot be modified. Calldata is typically preferred over
memory in external functions (though not required after version 0.6.9). Arrays and
structs with ``calldata`` data location can also be returned from functions, but it
is not possible to allocate such types.
.. note:: .. note::
Prior to version 0.5.0 the data location could be omitted, and would default to different locations Prior to version 0.5.0 the data location could be omitted, and would default to different locations
depending on the kind of variable, function type, etc., but all complex types must now give an explicit depending on the kind of variable, function type, etc., but all complex types must now give an explicit
data location. data location.
.. note::
If you can, try to use ``calldata`` as data location because it will avoid copies and
also makes sure that the data cannot be modified. Arrays and structs with ``calldata``
data location can also be returned from functions, but it is not possible to
allocate such types.
.. _data-location-assignment: .. _data-location-assignment:
Data location and assignment behaviour Data location and assignment behaviour