/// Figure out what size block we'll need to fulfill an allocation
/// request.  This is deterministic, and it does not depend on what
/// we've already allocated.  In particular, it's important to be able
/// to calculate the same `allocation_size` when freeing memory as we
/// did when allocating it, or everything will break horribly.
Figure out what size block we'll need to fulfill an allocation
request.  This is deterministic, and it does not depend on what
we've already allocated.  In particular, it's important to be able
to calculate the same `allocation_size` when freeing memory as we
did when allocating it, or everything will break horribly.
Figure out what size block we ' ll need to fulfill an allocation request . This is deterministic and it does not depend on what we ' ve already allocated . In particular it ' s important to be able to calculate the same ` allocation_size ` when freeing memory as we did when allocating it or everything will break horribly .
fn allocation_size(&self, mut size: usize, align: usize) -> Result<usize, AllocationSizeError> {
        // Sorry, we don't support weird alignments.
        if !align.is_power_of_two() {
            return Err(AllocationSizeError::BadAlignment);
        }
        // We can't align any more precisely than our heap base alignment
        // without getting much too clever, so don't bother.
        if align > MIN_HEAP_ALIGN {
            return Err(AllocationSizeError::BadAlignment);
        }
        // We're automatically aligned to `size` because of how our heap is
        // sub-divided, but if we need a larger alignment, we can only do
        // it be allocating more memory.
        if align > size {
            size = align;
        }
        // We can't allocate blocks smaller than `min_block_size`.
        size = max(size, self.min_block_size);
        // Round up to the next power of two.
        size = size.next_power_of_two();
        // We can't allocate a block bigger than our heap.
        if size > self.heap_size {
            return Err(AllocationSizeError::TooLarge);
        }
        Ok(size)
    }
fn allocation_size ( & self , mut size : usize , align : usize ) -> Result < usize , AllocationSizeError > { // Sorry, we don't support weird alignments. if ! align . is_power_of_two ( ) { return Err ( AllocationSizeError :: BadAlignment ) ; } // We can't align any more precisely than our heap base alignment // without getting much too clever, so don't bother. if align > MIN_HEAP_ALIGN { return Err ( AllocationSizeError :: BadAlignment ) ; } // We're automatically aligned to `size` because of how our heap is // sub-divided, but if we need a larger alignment, we can only do // it be allocating more memory. if align > size { size = align ; } // We can't allocate blocks smaller than `min_block_size`. size = max ( size , self . min_block_size ) ; // Round up to the next power of two. size = size . next_power_of_two ( ) ; // We can't allocate a block bigger than our heap. if size > self . heap_size { return Err ( AllocationSizeError :: TooLarge ) ; } Ok ( size ) }
Figure out what size block we'll need to fulfill an allocation
request.
Figure out what size block we ' ll need to fulfill an allocation request .
&self
size
usize
align
usize