github.com/likebike/go--@v0.0.0-20190911215757-0bd925d16e96/go/src/runtime/msize.go (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Malloc small size classes.
     6  //
     7  // See malloc.go for overview.
     8  // See also mksizeclasses.go for how we decide what size classes to use.
     9  
    10  package runtime
    11  
    12  // Returns size of the memory block that mallocgc will allocate if you ask for the size.
    13  func roundupsize(size uintptr) uintptr {
    14  	if size < _MaxSmallSize {
    15  		if size <= smallSizeMax-8 {
    16  			return uintptr(class_to_size[size_to_class8[(size+smallSizeDiv-1)/smallSizeDiv]])
    17  		} else {
    18  			return uintptr(class_to_size[size_to_class128[(size-smallSizeMax+largeSizeDiv-1)/largeSizeDiv]])
    19  		}
    20  	}
    21  	if size+_PageSize < size {
    22  		return size
    23  	}
    24  	return round(size, _PageSize)
    25  }