(kind: MemoryType, backend: &MemoryBackend)
| 20 | const COPY_CHUNK_SIZE: usize = 4 * 1024; |
| 21 | |
| 22 | pub(crate) fn new(kind: MemoryType, backend: &MemoryBackend) -> Result<Self> { |
| 23 | assert!(kind.page_count_initial() <= kind.page_count_max()); |
| 24 | |
| 25 | let initial_len = usize::try_from(kind.initial_size()) |
| 26 | .map_err(|_| Error::UnsupportedFeature("memory size exceeds the host address space"))?; |
| 27 | |
| 28 | crate::log::debug!( |
| 29 | "initializing memory with {} pages of {} bytes", |
| 30 | kind.page_count_initial(), |
| 31 | kind.page_size() |
| 32 | ); |
| 33 | |
| 34 | let storage = backend.create(kind, initial_len)?; |
| 35 | if storage.len() != initial_len { |
| 36 | return Err(Error::Other(format!( |
| 37 | "memory backend returned {} bytes for a memory that requires {initial_len}", |
| 38 | storage.len() |
| 39 | ))); |
| 40 | } |
| 41 | |
| 42 | Ok(Self { kind, inner: storage, page_count: kind.page_count_initial() as usize }) |
| 43 | } |
| 44 | |
| 45 | pub(crate) fn new_lazy(kind: MemoryType, backend: &MemoryBackend) -> Result<Self> { |
| 46 | assert!(kind.page_count_initial() <= kind.page_count_max()); |
nothing calls this directly
no test coverage detected