pub unsafe fn deallocate(&mut self, ptr: *mut u8, layout: Layout) {
        let initial_order = self
            .allocation_order(layout.size(), layout.align())
            .expect("Tried to dispose of invalid block");

        // The fun part: When deallocating a block, we also want to check
        // to see if its "buddy" is on the free list.  If the buddy block
        // is also free, we merge them and continue walking up.
        //
        // `block` is the biggest merged block we have so far.
        let mut block = ptr;
        for order in initial_order..self.free_lists.len() {
            // Would this block have a buddy?
            if let Some(buddy) = self.buddy(order, block) {
                // Is this block's buddy free?
                if self.free_list_remove(order, buddy) {
                    // Merge them!  The lower address of the two is the
                    // newly-merged block.  Then we want to try again.
                    block = min(block, buddy);
                    continue;
                }
            }

            // If we reach here, we didn't find a buddy block of this size,
            // so take what we've got and mark it as free.
            self.free_list_insert(order, block);
            return;
        }
    }
/// Deallocate a block allocated using `allocate`.
///
/// # Safety
/// `ptr` and `layout` must match what was passed to / returned from `allocate`,
/// or our heap will be corrupted.
Deallocate a block allocated using `allocate`.
Deallocate a block allocated using ` allocate ` .
pub unsafe fn deallocate(&mut self, ptr: *mut u8, layout: Layout) {
        let initial_order = self
            .allocation_order(layout.size(), layout.align())
            .expect("Tried to dispose of invalid block");
        // The fun part: When deallocating a block, we also want to check
        // to see if its "buddy" is on the free list.  If the buddy block
        // is also free, we merge them and continue walking up.
        //
        // `block` is the biggest merged block we have so far.
        let mut block = ptr;
        for order in initial_order..self.free_lists.len() {
            // Would this block have a buddy?
            if let Some(buddy) = self.buddy(order, block) {
                // Is this block's buddy free?
                if self.free_list_remove(order, buddy) {
                    // Merge them!  The lower address of the two is the
                    // newly-merged block.  Then we want to try again.
                    block = min(block, buddy);
                    continue;
                }
            }
            // If we reach here, we didn't find a buddy block of this size,
            // so take what we've got and mark it as free.
            self.free_list_insert(order, block);
            return;
        }
    }
pub unsafe fn deallocate ( & mut self , ptr : * mut u8 , layout : Layout ) { let initial_order = self . allocation_order ( layout . size ( ) , layout . align ( ) ) . expect ( " " ) ; // The fun part: When deallocating a block, we also want to check // to see if its "buddy" is on the free list.  If the buddy block // is also free, we merge them and continue walking up. // // `block` is the biggest merged block we have so far. let mut block = ptr ; for order in initial_order .. self . free_lists . len ( ) { // Would this block have a buddy? if let Some ( buddy ) = self . buddy ( order , block ) { // Is this block's buddy free? if self . free_list_remove ( order , buddy ) { // Merge them!  The lower address of the two is the // newly-merged block.  Then we want to try again. block = min ( block , buddy ) ; continue ; } } // If we reach here, we didn't find a buddy block of this size, // so take what we've got and mark it as free. self . free_list_insert ( order , block ) ; return ; } }
Deallocate a block allocated using `allocate`.
Deallocate a block allocated using ` allocate ` .
&mut self
ptr
*mut u8
layout
Layout
&mut self
ptr
*mut u8
layout
Layout
safety
`ptr` and `layout` must match what was passed to / returned from `allocate`,
or our heap will be corrupted.
` ptr ` and ` layout ` must match what was passed to / returned from ` allocate ` or our heap will be corrupted .