-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add EnvBase::augment_err_result to help gather debug info. * Charge linear memory growth delta to budget, not the total new size. * Add an example that does allocation using the SDK's alloc function. --------- Co-authored-by: Jay Geng <[email protected]>
- Loading branch information
Showing
13 changed files
with
127 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ resolver = "2" | |
members = [ | ||
"add_i32", | ||
"add_f32", | ||
"alloc", | ||
"auth", | ||
"fib", | ||
"contract_data", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "example_alloc" | ||
version = "0.0.0" | ||
authors = ["Stellar Development Foundation <[email protected]>"] | ||
license = "Apache-2.0" | ||
edition = "2021" | ||
publish = false | ||
rust-version = "1.65" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
doctest = false | ||
|
||
[dependencies] | ||
soroban-sdk = { workspace = true, features = ["alloc"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![no_std] | ||
use soroban_sdk::{contract, contractimpl, Env}; | ||
|
||
extern crate alloc; | ||
|
||
#[contract] | ||
pub struct AllocContract; | ||
|
||
struct Large { | ||
x: u32, | ||
space: [u8;4096] | ||
} | ||
|
||
#[contractimpl] | ||
impl AllocContract { | ||
/// Allocates a temporary vector holding values (0..count), then computes | ||
/// and returns their sum. Also allocates these values in a "large" | ||
/// structure (with a bunch of pointless padding) to ensure the contract | ||
/// allocates lots of memory. | ||
pub fn sum(_env: Env, count: u32) -> u32 { | ||
let mut v1 = alloc::vec![]; | ||
for i in 0..count { | ||
v1.push(Large{x: i, space: [0u8; 4096]}) | ||
} | ||
v1.iter().map(|l| l.x + l.space[0] as u32).sum() | ||
} | ||
} |
Binary file not shown.