github.com/pidato/unsafe@v0.1.4/memory/heap/freelist.go (about) 1 package heap 2 3 type Freelist struct { 4 } 5 6 var ( 7 smallClasses = [...]Class{ 8 {0, 31, 12}, {1, 30, 16}, {2, 29, 20}, 9 {3, 28, 24}, {4, 27, 28}, {5, 26, 36}, 10 {6, 25, 44}, {7, 24, 60}, {8, 23, 76}, 11 {9, 22, 92}, {10, 21, 124}, {11, 20, 156}, 12 {12, 19, 188}, {13, 18, 220}, {14, 17, 252}, 13 {15, 16, 300}, {16, 15, 364}, {17, 14, 428}, 14 {18, 13, 508}, {19, 12, 764}, {20, 11, 1020}, 15 {21, 10, 1280}, {22, 9, 1532}, {23, 8, 2044}, 16 {24, 7, 4092}, {25, 6, 8188}, {26, 5, 16380}, 17 } 18 smallClassesSmall = [...]Class{ 19 {0, 31, 12}, {0, 31, 12}, {0, 31, 12}, 20 {0, 31, 12}, {1, 30, 16}, {2, 29, 20}, 21 {3, 28, 24}, {4, 27, 28}, {5, 26, 36}, 22 {5, 26, 36}, {6, 25, 44}, {6, 25, 44}, 23 {7, 24, 60}, {7, 24, 60}, {7, 24, 60}, 24 {7, 24, 60}, {8, 23, 76}, {8, 23, 76}, 25 {8, 23, 76}, {8, 23, 76}, {9, 22, 92}, 26 {9, 22, 92}, {9, 22, 92}, {9, 22, 92}, 27 {10, 21, 124}, {10, 21, 124}, {10, 21, 124}, 28 {10, 21, 124}, {10, 21, 124}, {10, 21, 124}, 29 {10, 21, 124}, {10, 21, 124}, {11, 20, 156}, 30 {11, 20, 156}, {11, 20, 156}, {11, 20, 156}, 31 {11, 20, 156}, {11, 20, 156}, {11, 20, 156}, 32 {11, 20, 156}, {12, 19, 188}, {12, 19, 188}, 33 {12, 19, 188}, {12, 19, 188}, {12, 19, 188}, 34 {12, 19, 188}, {12, 19, 188}, {12, 19, 188}, 35 {13, 18, 220}, {13, 18, 220}, {13, 18, 220}, 36 {13, 18, 220}, {13, 18, 220}, {13, 18, 220}, 37 {13, 18, 220}, {13, 18, 220}, {14, 17, 252}, 38 {14, 17, 252}, {14, 17, 252}, {14, 17, 252}, 39 {14, 17, 252}, {14, 17, 252}, {14, 17, 252}, 40 {14, 17, 252}, {15, 16, 300}, {15, 16, 300}, 41 {15, 16, 300}, {15, 16, 300}, {15, 16, 300}, 42 {15, 16, 300}, {15, 16, 300}, {15, 16, 300}, 43 {15, 16, 300}, {15, 16, 300}, {15, 16, 300}, 44 {15, 16, 300}, {16, 15, 364}, {16, 15, 364}, 45 {16, 15, 364}, {16, 15, 364}, {16, 15, 364}, 46 {16, 15, 364}, {16, 15, 364}, {16, 15, 364}, 47 {16, 15, 364}, {16, 15, 364}, {16, 15, 364}, 48 {16, 15, 364}, {16, 15, 364}, {16, 15, 364}, 49 {16, 15, 364}, {16, 15, 364}, {17, 14, 428}, 50 {17, 14, 428}, {17, 14, 428}, {17, 14, 428}, 51 {17, 14, 428}, {17, 14, 428}, {17, 14, 428}, 52 {17, 14, 428}, {17, 14, 428}, {17, 14, 428}, 53 {17, 14, 428}, {17, 14, 428}, {17, 14, 428}, 54 {17, 14, 428}, {17, 14, 428}, {17, 14, 428}, 55 {18, 13, 508}, {18, 13, 508}, {18, 13, 508}, 56 {18, 13, 508}, {18, 13, 508}, {18, 13, 508}, 57 {18, 13, 508}, {18, 13, 508}, {18, 13, 508}, 58 {18, 13, 508}, {18, 13, 508}, {18, 13, 508}, 59 {18, 13, 508}, {18, 13, 508}, {18, 13, 508}, 60 {18, 13, 508}, {18, 13, 508}, {18, 13, 508}, 61 {18, 13, 508}, 62 } 63 smallClassesMedium = [...]Class{ 64 {18, 13, 508}, {19, 12, 764}, {20, 11, 1020}, 65 {21, 10, 1280}, {22, 9, 1532}, {23, 8, 2044}, 66 {23, 8, 2044}, {24, 7, 4092}, {24, 7, 4092}, 67 {24, 7, 4092}, {24, 7, 4092}, {24, 7, 4092}, 68 {24, 7, 4092}, {24, 7, 4092}, {24, 7, 4092}, 69 {25, 6, 8188}, {25, 6, 8188}, {25, 6, 8188}, 70 {25, 6, 8188}, {25, 6, 8188}, {25, 6, 8188}, 71 {25, 6, 8188}, {25, 6, 8188}, {25, 6, 8188}, 72 {25, 6, 8188}, {25, 6, 8188}, {25, 6, 8188}, 73 {25, 6, 8188}, {25, 6, 8188}, {25, 6, 8188}, 74 {25, 6, 8188}, {26, 5, 16380}, {26, 5, 16380}, 75 {26, 5, 16380}, {26, 5, 16380}, {26, 5, 16380}, 76 {26, 5, 16380}, {26, 5, 16380}, {26, 5, 16380}, 77 {26, 5, 16380}, {26, 5, 16380}, {26, 5, 16380}, 78 {26, 5, 16380}, {26, 5, 16380}, {26, 5, 16380}, 79 {26, 5, 16380}, {26, 5, 16380}, {26, 5, 16380}, 80 {26, 5, 16380}, {26, 5, 16380}, {26, 5, 16380}, 81 {26, 5, 16380}, {26, 5, 16380}, {26, 5, 16380}, 82 {26, 5, 16380}, {26, 5, 16380}, {26, 5, 16380}, 83 {26, 5, 16380}, {26, 5, 16380}, {26, 5, 16380}, 84 {26, 5, 16380}, {26, 5, 16380}, 85 } 86 ) 87 88 func SmallAllocSize(size uintptr) Class { 89 if size < 509 { 90 index := divRoundUp(size, 4) 91 return smallClasses[index] 92 } 93 if size < 16381 { 94 index := divRoundUp(size-508, 256) 95 return smallClassesMedium[index] 96 } 97 return Class{0, 0, 0} 98 } 99 100 type FreelistSmall16 struct { 101 fl uint32 102 classes [30]uint16 103 } 104 105 func (fls *FreelistSmall16) AllocSize(size uintptr) Class { 106 return SmallAllocSize(size) 107 } 108 109 type Freelist64 struct { 110 }