Source file
src/runtime/msize.go
1
2
3
4
5
6
7
8
9
10 package runtime
11
12
13
14 func roundupsize(size uintptr, noscan bool) (reqSize uintptr) {
15 reqSize = size
16 if reqSize <= maxSmallSize-mallocHeaderSize {
17
18 if !noscan && reqSize > minSizeForMallocHeader {
19 reqSize += mallocHeaderSize
20 }
21
22
23 if reqSize <= smallSizeMax-8 {
24 return uintptr(class_to_size[size_to_class8[divRoundUp(reqSize, smallSizeDiv)]]) - (reqSize - size)
25 }
26 return uintptr(class_to_size[size_to_class128[divRoundUp(reqSize-smallSizeMax, largeSizeDiv)]]) - (reqSize - size)
27 }
28
29 reqSize += pageSize - 1
30 if reqSize < size {
31 return size
32 }
33 return reqSize &^ (pageSize - 1)
34 }
35
View as plain text