Lines Matching refs:Memory
17 /// Error for out of bounds [`Memory`] access.
45 /// # `Memory` and Safety
48 /// safe methods of interacting with a [`Memory`]:
50 /// * [`Memory::read`]
51 /// * [`Memory::write`]
52 /// * [`Memory::data`]
53 /// * [`Memory::data_mut`]
62 /// If you'd like to dip your toes into handling [`Memory`] in a more raw
80 /// [`Memory`] if you can. It's not advised to use raw pointers or `unsafe`
86 /// use wasmtime::{Memory, Store, MemoryAccessError};
88 /// // Memory can be read and written safely with the `Memory::read` and
89 /// // `Memory::write` methods.
91 /// fn safe_examples(mem: Memory, store: &mut Store<()>) -> Result<(), MemoryAccessError> {
108 /// **unsafe** usages of `Memory`. Do not do these things!
111 /// use wasmtime::{Memory, Result, Store};
116 /// unsafe fn unsafe_examples(mem: Memory, store: &mut Store<()>) -> Result<()> {
118 /// // `Memory::grow` function. This can relocate memory which causes any
138 /// // The `Memory` type may be stored in other locations, so if you hand
140 /// // `Memory::grow` or similar, so it's not enough to just audit code for
141 /// // calls to `Memory::grow`.
164 /// `Memory` and getting raw pointers inside of it:
177 /// `Memory` is pretty tricky and not recommended! It's highly recommended to
178 /// use the safe methods to interact with [`Memory`] whenever possible.
180 /// ## `Memory` Safety and Threads
198 /// One important point about concurrency is that while [`Memory::grow`] can
206 /// must be eagerly copied out. This means that [`Memory::data`] and
207 /// [`Memory::data_mut`] won't work in the future (they'll probably return an
209 /// recommended to use [`Memory::read`] and [`Memory::write`] which will still
213 pub struct Memory {
228 assert!(core::mem::size_of::<C>() == core::mem::size_of::<Memory>());
229 assert!(core::mem::align_of::<C>() == core::mem::align_of::<Memory>());
230 assert!(core::mem::offset_of!(Memory, instance) == 0);
233 impl Memory {
236 /// The `store` argument will be the owner of the returned [`Memory`]. All
244 /// using an async resource limiter, use [`Memory::new_async`] instead.
255 /// let memory = Memory::new(&mut store, memory_ty)?;
263 pub fn new(mut store: impl AsContextMut, ty: MemoryType) -> Result<Memory> {
271 /// Async variant of [`Memory::new`]. You must use this variant with
280 pub async fn new_async(mut store: impl AsContextMut, ty: MemoryType) -> Result<Memory> {
290 ) -> Result<Memory> {
413 /// Same as [`Memory::data_mut`], but also returns the `T` from the
417 /// `T` in the store as well as the memory behind this [`Memory`]. Using
418 /// [`Memory::data_mut`] would consider the entire store borrowed, whereas
450 /// [`Memory`] type.
467 /// a memory's page size via the [`Memory::page_size`] method.
477 /// [`Memory`] type.
495 /// a memory's page size via the [`Memory::page_size`] method.
520 /// size (as returned by [`Memory::data_size`]) will always be a multiple of
539 /// size (as returned by [`Memory::data_size`]) will always be a multiple of
559 /// this `Memory` instance. If successful this may relocate the memory and
560 /// cause [`Memory::data_ptr`] to return a new value. Additionally any
583 /// async resource limiter, use [`Memory::grow_async`] instead.
615 /// Async variant of [`Memory::grow`]. Required when using a
656 pub(crate) unsafe fn from_raw(instance: StoreInstanceId, index: DefinedMemoryIndex) -> Memory {
657 Memory { instance, index }
660 pub(crate) fn wasmtime_ty<'a>(&self, store: &'a StoreOpaque) -> &'a wasmtime_environ::Memory {
686 /// `StoreData` multiple times and becomes multiple `wasmtime::Memory`s,
695 /// which are used by wasmtime, e.g. inside ['Memory']. Such buffers are in
704 /// guard page. Additionally the safety concerns explained in ['Memory'], for
773 /// Memory created from this method should be zero filled.
787 /// This is much the same as a Wasm linear memory (i.e., [`Memory`]), but can be
878 /// [`Memory`] type.
913 /// this `Memory` instance. If successful this may relocate the memory and
914 /// cause [`Memory::data_ptr`] to return a new value. Additionally any
1058 // Assert that creating a memory via `Memory::new` respects the limits/tunables
1066 let mem = Memory::new(&mut store, ty).unwrap();
1089 // Each time we `get_memory`, we call `Memory::from_wasmtime` which adds