diff options
author | chriseth <c@ethdev.com> | 2016-03-18 18:46:08 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-03-18 18:46:08 +0800 |
commit | e8bef6fc01dd3f93429110cf1f92817e1a99152c (patch) | |
tree | 630eafcc6dbc63e32888235912a266b6b5f5484d | |
parent | 11d67369bd0faee2b84c94522355ac963d726f16 (diff) | |
parent | a81173be10cf821bd3c8db6d0c6f160a209a2c7b (diff) | |
download | dexon-solidity-e8bef6fc01dd3f93429110cf1f92817e1a99152c.tar.gz dexon-solidity-e8bef6fc01dd3f93429110cf1f92817e1a99152c.tar.zst dexon-solidity-e8bef6fc01dd3f93429110cf1f92817e1a99152c.zip |
Merge pull request #432 from chriseth/alloc
Allocating arrays.
-rw-r--r-- | docs/types.rst | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/docs/types.rst b/docs/types.rst index 13e2a23e..187f62c1 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -291,6 +291,27 @@ So `bytes` should always be preferred over `byte[]` because it is cheaper. that you are accessing the low-level bytes of the utf-8 representation, and not the individual characters! +.. index:: ! array;allocating, new + +Allocating Memory Arrays +^^^^^^^^^^^^^^^^^^^^^^^^ + +Creating arrays with variable length in memory can be done using the `new` keyword. +As opposed to storage arrays, it is **not** possible to resize memory arrays by assigning to +the `.length` member. + +:: + + contract C { + function f(uint len) { + uint[] memory a = new uint[](7); + bytes memory b = new bytes(len); + // Here we have a.length == 7 and b.length == len + a[6] = 8; + } + } + + .. index:: ! array;length, length, push, !array;push Members |