forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wasmtime: Introduce
{Module,Component}::resources_required
(bytecod…
…ealliance#6789) Returns a summary of the resources required to instantiate this module or component. Potential uses of the returned information: * Determining whether your pooling allocator configuration supports instantiating this module. * Deciding how many of which `Module` you want to instantiate within a fixed amount of resources, e.g. determining whether to create 5 instances of module X or 10 instances of module Y. Part of bytecodealliance#6627.
- Loading branch information
1 parent
31639dd
commit 53e5897
Showing
4 changed files
with
195 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/// A summary of the amount of resources required to instantiate a particular | ||
/// [`Module`][crate::Module] or [`Component`][crate::component::Component]. | ||
/// | ||
/// Example uses of this information: | ||
/// | ||
/// * Determining whether your pooling allocator configuration supports | ||
/// instantiating this module. | ||
/// | ||
/// * Deciding how many of which `Module` you want to instantiate within a | ||
/// fixed amount of resources, e.g. determining whether to create 5 | ||
/// instances of module `X` or 10 instances of module `Y`. | ||
pub struct ResourcesRequired { | ||
/// The number of memories that are required. | ||
pub num_memories: u32, | ||
/// The maximum initial size required by any memory, in units of Wasm pages. | ||
pub max_initial_memory_size: Option<u64>, | ||
/// The number of tables that are required. | ||
pub num_tables: u32, | ||
/// The maximum initial size required by any table. | ||
pub max_initial_table_size: Option<u32>, | ||
} | ||
|
||
impl ResourcesRequired { | ||
#[cfg(feature = "component-model")] | ||
pub(crate) fn add(&mut self, other: &ResourcesRequired) { | ||
self.num_memories += other.num_memories; | ||
self.max_initial_memory_size = | ||
std::cmp::max(self.max_initial_memory_size, other.max_initial_memory_size); | ||
self.num_tables += other.num_tables; | ||
self.max_initial_table_size = | ||
std::cmp::max(self.max_initial_table_size, other.max_initial_table_size); | ||
} | ||
} |