引用类型(Reference Types)

memory 不支持持久保存
storage 保留为变量 复杂类型如arrays和structs,有附加信息,‘data location’,提示存储在'memory'或者'storage'。函数参数默认使用memory,本地变量默认使用storage.
pragma solidity ^0.4.17;

contract C {
uint[] x; // 存储在storage function f(uint[] memoryArray) public { // memoryArray存储在memory
x = memoryArray; // 复制memoryArray到storage
var y = x; // y 存储在storage
y[7]; // 返回第8字符
y.length = 2; // 通过y修改x
delete x; // 清除数组,同时修改y
g(x); // 调用g,处理到x的引用
h(x); // 调用h,建立依赖,临时复制到memory
} function g(uint[] storage storageArray) internal {}
function h(uint[] memoryArray) public {}
}

数组

固定长度数组 T[k]
非固定长度数组 T[] 访问方法 x[2][1] bytes 和 string是特殊数组,string等同于bytes,但不不允许使用成员属性length和使用索引访问。 成员属性
length
push

在内存中建立数组

使用new关键字在内存中建立可变长度数组,相对于stroge中的数组,它不能使用length改变长度

pragma solidity ^0.4.16;

contract C {
function f(uint len) public pure {
uint[] memory a = new uint[] (7);
bytes memory b = new bytes (len);
// a.length == 7, b.length == len
a[6] = 8;
}
}

数组常量

数组常量只能通过表达式声明,不能批派到变量

pragma solidity ^0.4.16;

contract C {
function f() public pure {
g([uint(1), 2, 3]);
} function g(uint[3] _data) public pure {
// ...
}
} 以下是错误的
pragma solidity ^0.4.0; contract C {
function f() public {
// The next line creates a type error because uint[3] memory cannot be converted to uint[] memory.
uint[] x = [uint(1), 3, 4];
}
}

完整例子

pragma solidity ^0.4.16;

contract ArrayContract {
uint[2**20] m_aLotOfIntegers;
// Note that the following is not a pair of dynamic arrays but a
// dynamic array of pairs (i.e. of fixed size arrays of length two). bool[2][] m_pairsOfFlags; // newPairs is stored in memory - the default for function arguments
2function setAllFlagPairs(bool[2][] newPairs) public {
// assignment to a storage array replaces the complete array
m_pairsOfFlags = newPairs;
} function setFlagPair(uint index, bool flagA, bool flagB) public {
// access to a non-existing index will throw an exception
m_pairsOfFlags[index][0] = flagA;
m_pairsOfFlags[index][1] = flagB;
} function changeFlagArraySize(uint newSize) public {
// if the new size is smaller, removed array elements will be cleared
m_pairsOfFlags.length = newSize;
} function clear() public {
// these clear the arrays completely
delete m_pairsOfFlags;
delete m_aLotOfIntegers; // identical effect here
m_pairsOfFlags.length = 0;
} bytes m_byteData;
function byteArrays(bytes data) public {
// byte arrays ("bytes") are different as they are stored without padding,
// but can be treated identical to "uint8[]"
m_byteData = data;
m_byteData.length += 7;
m_byteData[3] = byte(8);
delete m_byteData[2];
} function addFlag(bool[2] flag) public returns (uint) {
return m_pairsOfFlags.push(flag);
} function createMemoryArray(uint size) public pure returns (bytes) {
// Dynamic memory arrays are created using `new`:
uint[2][] memory arrayOfPairs = new uint[2][](size); // Create a dynamic byte array:
bytes memory b = new bytes(200);
for (uint i = 0; i < b.length; i++)
b[i] = byte(i);
return b;
}
}

solidity语言4的更多相关文章

  1. 用solidity语言开发代币智能合约

    智能合约开发是以太坊编程的核心之一,而代币是区块链应用的关键环节,下面我们来用solidity语言开发一个代币合约的实例,希望对大家有帮助. 以太坊的应用被称为去中心化应用(DApp),DApp的开发 ...

  2. 第一行代码:以太坊(2)-使用Solidity语言开发和测试智能合约

    智能合约是以太坊的核心之一,用户可以利用智能合约实现更灵活的代币以及其他DApp.不过在深入讲解如何开发智能合约之前,需要先介绍一下以太坊中用于开发智能合约的Solidity语言,以及相关的开发和测试 ...

  3. Solidity语言系列教程

    Solidity 是一门面向合约的.为实现智能合约而创建的高级编程语言.这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的目的是能在 以太坊虚拟机(EVM) 上运行. ...

  4. solidity语言介绍以及开发环境准备

    solidity语言介绍以及开发环境准备   Solidity 是一门面向合约的.为实现智能合约而创建的高级编程语言.这门语言受到了 C++,Python 和 Javascript 语言的影响,设计的 ...

  5. 用C++生成solidity语言描述的buchi自动机的初级经验

    我的项目rvtool(https://github.com/Zeraka/rvtool)中增加了生成solidity语言格式的监控器的模块. solidity特殊之处在于,它是运行在以太坊虚拟机环境中 ...

  6. Solidity语言基础 和 Etherum ERC20合约基础

    1. 类型只能从第一次赋值中推断出来,因此以下代码中的循环是无限的,  小. for (var i = 0; i < 2000; i++) { ... } --- Solidity Types ...

  7. solidity语言

    IDE:Atom 插件:autocomplete-solidity 代码自动补齐   linter-solium,linter-solidity代码检查错误   language-ethereum支持 ...

  8. solidity语言14

    库(Libraries) 库类似合约,实现仅在专门地址部署一次,使用EVM的DELEGATECALL的功能重复使用的目的.意思是当库函数被调用后,代码执行在被调用的合约的环境.例如,使用this调用合 ...

  9. solidity语言13

    函数过载 合约内允许定义同名函数,但是输入参数不一致 pragma solidity ^0.4.17; contract A { function f(uint _in) public pure re ...

  10. solidity语言12

    View Functions 函数声明为视图,将无权修改状态 pragma solidity ^0.4.16; contract C { function f(uint a, uint b) publ ...

随机推荐

  1. P3704 [SDOI2017]数字表格 (莫比乌斯反演)

    [题目链接] https://www.luogu.org/problemnew/show/P3704 [题解] https://www.luogu.org/blog/cjyyb/solution-p3 ...

  2. 洛谷 P4859 && BZOJ3622: 已经没有什么好害怕的了

    题目描述 给出 \(n\) 个数 \(a_i\)​ ,以及 \(n\) 个数 \(b_i\)​ ,要求两两配对使得 \(a>b\) 的对数减去 \(a<b\) 的对数等于 \(k\) . ...

  3. ORA-28009: 应当以 SYSDBA 身份或 SYSOPER 身份建立 SYS 连接

    用 SQL*Plus 连接数据库的时候,除了用户名和密码外,还要在口令后面加一个主机字符串.如下: 请输入用户名:sys 口令:ANKoracle123,orcl as sysdba

  4. HDU_2082 找单词 【母函数的应用】

    题目: 假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50 ...

  5. c# MVC返回小驼峰Json(首字母小写)

    1.与前端交互时,前端总希望传过去的json字段名首字母小写,但是.net规范是首字线大写 如果就写了下面的转换方法 /// <summary> /// Poco类字段名转换成首字母小写的 ...

  6. sublim text3中的一些设置

    {    "dictionary": "Packages/Language - English/en_US.dic",    "font_face&q ...

  7. 【网络】CCNA实验一:Vlan、Trunk

    要求: 1:不同楼层物理隔离,但逻辑相连 2:相同楼层物理相连,但逻辑隔离 3:主机可以动态获取IP地址 4:不同VLAN间可以进行通信 5:主机最终访问www.esafenet.com弹出" ...

  8. Percona Mysql备份

    介绍 Percona是唯一一款开源.免费的mysql热备份工具,实现了对InnoDB数据库的非阻塞式的备份.有如下优势:1.完整.快速.可靠的备份2.备份期间不打断事务执行(innodb引擎)3.备份 ...

  9. nginx 服务器配置文件指令

    localtion 配置        语法结构: location [ =  ~  ~* ^~ ] uri{ ... }        uri 变量是带匹配的请求字符, 可以是不含正则表达的字符串, ...

  10. 牛客网Java刷题知识点之内存溢出和内存泄漏的概念、区别、内存泄露产生原因、内存溢出产生原因、内存泄露解决方案、内存溢出解决方案

    不多说,直接上干货! 福利 => 每天都推送 欢迎大家,关注微信扫码并加入我的4个微信公众号:   大数据躺过的坑      Java从入门到架构师      人工智能躺过的坑          ...