/// Increases the size of the linear memory by given number of pages.
/// Returns previous memory size if succeeds.
///
/// # Errors
///
/// Returns `Err` if attempted to allocate more memory than permited by the limit.
Increases the size of the linear memory by given number of pages.
Returns previous memory size if succeeds.
Increases the size of the linear memory by given number of pages . Returns previous memory size if succeeds .
pub fn grow(&self, additional: Pages) -> Result<Pages, Error> {
		let size_before_grow: Pages = self.current_size();
		if additional == Pages(0) {
			return Ok(size_before_grow);
		}
		if additional > Pages(65536) {
			return Err(Error::Memory(format!(
				"Trying to grow memory by more than 65536 pages"
			)));
		}
		let new_size: Pages = size_before_grow + additional;
		let maximum = self.maximum.unwrap_or(LINEAR_MEMORY_MAX_PAGES);
		if new_size > maximum {
			return Err(Error::Memory(format!(
				"Trying to grow memory by {} pages when already have {}",
				additional.0, size_before_grow.0,
			)));
		}
		// Resize underlying buffer up to a new size filling newly allocated space with zeroes.
		// This size is guaranteed to be larger than current size.
		let new_buffer_length: Bytes = new_size.into();
		{
			let mut buffer = self.buffer.borrow_mut();
			debug_assert!(new_buffer_length.0 > buffer.len());
			buffer.resize(new_buffer_length.0, 0);
		}
		Ok(size_before_grow)
	}
pub fn grow ( & self , additional : Pages ) -> Result < Pages , Error > { let size_before_grow : Pages = self . current_size ( ) ; if additional == Pages ( 0 ) { return Ok ( size_before_grow ) ; } if additional > Pages ( 65536 ) { return Err ( Error :: Memory ( format ! ( " " ) ) ) ; } let new_size : Pages = size_before_grow + additional ; let maximum = self . maximum . unwrap_or ( LINEAR_MEMORY_MAX_PAGES ) ; if new_size > maximum { return Err ( Error :: Memory ( format ! ( " " additional 0 size_before_grow 0 ) ) ) ; } // Resize underlying buffer up to a new size filling newly allocated space with zeroes. // This size is guaranteed to be larger than current size. let new_buffer_length : Bytes = new_size . into ( ) ; { let mut buffer = self . buffer . borrow_mut ( ) ; debug_assert ! ( new_buffer_length 0 buffer len ( ) ) ; buffer . resize ( new_buffer_length . 0 , 0 ) ; } Ok ( size_before_grow ) }
Increases the size of the linear memory by given number of pages.
Increases the size of the linear memory by given number of pages .
&self
additional
Pages
errors
Returns `Err` if attempted to allocate more memory than permited by the limit.
Returns ` Err ` if attempted to allocate more memory than permited by the limit .