fn alloc(&mut self, layout: Layout) -> Option<usize> {
        let alloc_start = self.next;

        let aligned_size = layout.pad_to_align().size();
        let alloc_end = alloc_start.checked_add(aligned_size)?;

        if alloc_end > self.upper_limit {
            let required_pages = (aligned_size + PAGE_SIZE - 1) / PAGE_SIZE;
            let page_start = self.request_pages(required_pages)?;

            self.upper_limit = required_pages
                .checked_mul(PAGE_SIZE)
                .and_then(|pages| page_start.checked_add(pages))?;
            self.next = page_start.checked_add(aligned_size)?;

            Some(page_start)
        } else {
            self.next = alloc_end;
            Some(alloc_start)
        }
    }
/// Tries to allocate enough memory on the heap for the given `Layout`. If there is not enough
/// room on the heap it'll try and grow it by a page.
///
/// Note: This implementation results in internal fragmentation when allocating across pages.
Tries to allocate enough memory on the heap for the given `Layout`. If there is not enough
room on the heap it'll try and grow it by a page.

This implementation results in internal fragmentation when allocating across pages.
Tries to allocate enough memory on the heap for the given ` Layout ` . If there is not enough room on the heap it ' ll try and grow it by a page . This implementation results in internal fragmentation when allocating across pages .
fn alloc(&mut self, layout: Layout) -> Option<usize> {
        let alloc_start = self.next;
        let aligned_size = layout.pad_to_align().size();
        let alloc_end = alloc_start.checked_add(aligned_size)?;
        if alloc_end > self.upper_limit {
            let required_pages = (aligned_size + PAGE_SIZE - 1) / PAGE_SIZE;
            let page_start = self.request_pages(required_pages)?;
            self.upper_limit = required_pages
                .checked_mul(PAGE_SIZE)
                .and_then(|pages| page_start.checked_add(pages))?;
            self.next = page_start.checked_add(aligned_size)?;
            Some(page_start)
        } else {
            self.next = alloc_end;
            Some(alloc_start)
        }
    }
fn alloc ( & mut self , layout : Layout ) -> Option < usize > { let alloc_start = self . next ; let aligned_size = layout . pad_to_align ( ) . size ( ) ; let alloc_end = alloc_start . checked_add ( aligned_size ) ? ; if alloc_end > self . upper_limit { let required_pages = ( aligned_size + PAGE_SIZE - 1 ) / PAGE_SIZE ; let page_start = self . request_pages ( required_pages ) ? ; self . upper_limit = required_pages . checked_mul ( PAGE_SIZE ) . and_then ( | pages | page_start . checked_add ( pages ) ) ? ; self . next = page_start . checked_add ( aligned_size ) ? ; Some ( page_start ) } else { self . next = alloc_end ; Some ( alloc_start ) } }
Tries to allocate enough memory on the heap for the given `Layout`.
Tries to allocate enough memory on the heap for the given ` Layout ` .
&mut self
layout
Layout