Merge pull request #432 from chriseth/alloc

Allocating arrays.
This commit is contained in:
chriseth 2016-03-18 11:46:08 +01:00
commit e8bef6fc01

View File

@ -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