pub fn grow(&mut self, add_pages: u32) -> Option<u32> {
        let new_pages = match self.current.checked_add(add_pages) {
            Some(new_pages) => new_pages,
            None => return None,
        };
        if let Some(val) = self.maximum {
            if new_pages > val {
                return None;
            }
        } else {
            // Wasm linear memories are never allowed to grow beyond what is
            // indexable. If the memory has no maximum, enforce the greatest
            // limit here.
            if new_pages >= 65536 {
                return None;
            }
        }

        let prev_pages = self.current;
        let new_bytes = (new_pages * PAGE_SIZE) as usize;

        if self.mmap.len() < new_bytes {
            // If we have no maximum, this is a "dynamic" heap, and it's allowed
            // to move.
            assert!(self.maximum.is_none());
            let mut new_mmap = memmap::MmapMut::map_anon(new_bytes).unwrap();
            new_mmap.copy_from_slice(&self.mmap);
            self.mmap = new_mmap;
        }

        self.current = new_pages;

        // Ensure that newly allocated area is zeroed.
        let new_start_offset = (prev_pages * PAGE_SIZE) as usize;
        let new_end_offset = (new_pages * PAGE_SIZE) as usize;
        for i in new_start_offset..new_end_offset {
            assert!(self.mmap[i] == 0);
        }

        Some(prev_pages)
    }
/// Grow memory by the specified amount of pages.
///
/// Returns `None` if memory can't be grown by the specified amount
/// of pages.
Grow memory by the specified amount of pages.
Returns `None` if memory can't be grown by the specified amount
of pages.
Grow memory by the specified amount of pages . Returns ` None ` if memory can ' t be grown by the specified amount of pages .
pub fn grow(&mut self, add_pages: u32) -> Option<u32> {
        let new_pages = match self.current.checked_add(add_pages) {
            Some(new_pages) => new_pages,
            None => return None,
        };
        if let Some(val) = self.maximum {
            if new_pages > val {
                return None;
            }
        } else {
            // Wasm linear memories are never allowed to grow beyond what is
            // indexable. If the memory has no maximum, enforce the greatest
            // limit here.
            if new_pages >= 65536 {
                return None;
            }
        }
        let prev_pages = self.current;
        let new_bytes = (new_pages * PAGE_SIZE) as usize;
        if self.mmap.len() < new_bytes {
            // If we have no maximum, this is a "dynamic" heap, and it's allowed
            // to move.
            assert!(self.maximum.is_none());
            let mut new_mmap = memmap::MmapMut::map_anon(new_bytes).unwrap();
            new_mmap.copy_from_slice(&self.mmap);
            self.mmap = new_mmap;
        }
        self.current = new_pages;
        // Ensure that newly allocated area is zeroed.
        let new_start_offset = (prev_pages * PAGE_SIZE) as usize;
        let new_end_offset = (new_pages * PAGE_SIZE) as usize;
        for i in new_start_offset..new_end_offset {
            assert!(self.mmap[i] == 0);
        }
        Some(prev_pages)
    }
pub fn grow ( & mut self , add_pages : u32 ) -> Option < u32 > { let new_pages = match self . current . checked_add ( add_pages ) { Some ( new_pages ) => new_pages , None => return None , } ; if let Some ( val ) = self . maximum { if new_pages > val { return None ; } } else { // Wasm linear memories are never allowed to grow beyond what is // indexable. If the memory has no maximum, enforce the greatest // limit here. if new_pages >= 65536 { return None ; } } let prev_pages = self . current ; let new_bytes = ( new_pages * PAGE_SIZE ) as usize ; if self . mmap . len ( ) < new_bytes { // If we have no maximum, this is a "dynamic" heap, and it's allowed // to move. assert ! ( self maximum is_none ( ) ) ; let mut new_mmap = memmap :: MmapMut :: map_anon ( new_bytes ) . unwrap ( ) ; new_mmap . copy_from_slice ( & self . mmap ) ; self . mmap = new_mmap ; } self . current = new_pages ; // Ensure that newly allocated area is zeroed. let new_start_offset = ( prev_pages * PAGE_SIZE ) as usize ; let new_end_offset = ( new_pages * PAGE_SIZE ) as usize ; for i in new_start_offset .. new_end_offset { assert ! ( self mmap [ i ] 0 ) ; } Some ( prev_pages ) }
Grow memory by the specified amount of pages.
Grow memory by the specified amount of pages .
&mut self
add_pages
u32
&mut self
add_pages
u32