引用类型(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. 【实战】简述一次挖XSS的经历

    值守尤其是夜班真的是件痛苦的事情呀,献给还在值守岗位上奋斗的小伙伴们. 简单试了前面几个参数,发现c0-id这个参数值在响应包里有回显,截图如下: 把c0-id参数值改为xss,响应包内容也随之变化, ...

  2. mutillidae2.6.48部署到phpstudy

    废话不多说,先上链接 mutillidae2.6.48链接: https://pan.baidu.com/s/1hssyiVy 密码: pw67 phpstudy2016.exe链接: https:/ ...

  3. 分享一个js方法

    这是一个关于参数合并的方法,这个场景也经常遇到,比如我们现在要对微信小程序的wx.request进行再一次封装,会涉及到一些默认的参数和每次使用自己传递的参数合并问题,分享代码. var extend ...

  4. PIE SDK栅格图层渲染变化事件监听

    1. 功能简介 通过PIE SDK加载图层后,会默认的赋值给数据一个渲染.当用户重新给数据赋值Render或改变数据显示效果时,会触发渲染变化事件. 所谓的事件监听是在事件触发时,将执行用户指定的函数 ...

  5. python查看模块版本及所在文件夹

    # 以Numpy为例 第一种方法:import numpy as np np.__version__ >>> '1.12.1' np.__file__ >>> '/ ...

  6. unity文件 PlayerPrefs.SetInt 保存 And PlayerPrefs.GetInt读取

    unity文件保存读取PlayerPrefs.SetInt   And  PlayerPrefs.GetInt using UnityEngine; using System.Collections; ...

  7. Fedora中安装VLC播放器

    需要在机器上安装VLC,无奈不能直接通过yum安装,网上搜了一下,直接安装成功,其实挺简单的: 我的机器是Fedora15,其他的类似: ------------------------- 首先:su ...

  8. 记录: Win10+Ubuntu18.04双系统安装

    在重装windows系统的时候顺便将ubuntu也重装了. window 10 安装 制作USB启动盘 到"微软中国下载中心"(http://www.microsoft.com/z ...

  9. 游戏源码--Unity开源Moba游戏-服务器-客户端完整V1.0

    http://www.manew.com/thread-111658-1-1.html

  10. Java面试题03-访问权限控制

    Java面试题03-访问权限控制 1. Java中的包主要是为了防止类文件命名冲突以及方便进行代码组织和管理,因此采用域名倒置的方式来进行命名: 2. Java解释器的运行过程:首先找到环境变量CLA ...