Skip to content

Commit

Permalink
set stack size to reduce initial memory in generated wasm file (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
laizy authored Mar 16, 2019
1 parent 71b0b5c commit a62bb30
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ pub fn invoke() {
```

4. compile contract:
since the default stack size is 1M, which is too large for contract, we need reduce it, 32kb is enough for most usecase.
```
cargo build --release --target wasm32-unknown-unknown
RUSTFLAGS="-C link-arg=-zstack-size=32768" cargo build --release --target wasm32-unknown-unknown
```

## Procedural Macros
Expand Down
4 changes: 3 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ pub fn invoke() {
runtime::ret(b"hello, world");
}
```
4. 合约编译:`cargo build --release --target wasm32-unknown-unknown`
4. 合约编译:
由于rustc编译默认设置的栈内存大小是1M,这对于大型软件程序来说比较合理,但对合约来说是巨大的浪费,因此在编译时设置下栈的大小,32kb对于绝大多数合约来说是够用的。
`RUSTFLAGS="-C link-arg=-zstack-size=32768" cargo build --release --target wasm32-unknown-unknown`

## 代码生成宏
合约的编写往往是先从输入参数的字节数组中解析出具体调用的方法和调用参数,然后跳转到对应的函数中执行,最终将执行结果序列化为字节数组返回。这和web服务器从网络上获取字节流,解析出具体的请求,执行对应的处理函数并将结果序列化为字节流发送回网络的工作方式是类似的。因此可以像web开发框架一样将这样的固定又繁琐工作统一处理,使合约的开发者专注于合约本身功能的开发。`ontio_std`提供了代码生成宏,可以根据合约接口在编译期自动生成辅助性代码。采用代码生成宏的合约基本结构如下:
Expand Down

0 comments on commit a62bb30

Please sign in to comment.