Small objects are as small as 8 bytes, and increase in size by at most 25% to limit internal fragmentation. Small object sizes are regularly spaced: the sizes are 8, 10, 12, 14, 16, 20, 24, . . . , 224, and their sizes take the form k · 2i for 4 ≤ k ≤ 7 and 1 ≤ i ≤ 5. In other words, a small object size, when written in binary is a 1, followed by two arbitrary digits, followed by zeros. Thus bin 0 contains 8-byte objects, bin 1 contains 10-byte objects, and so forth. To compute the bin number from a small size can be done with bit hacking in O(1) operations.
以下程式碼轉換 size 為 bin number,透過 clz() 可得到一個數值用二進位表示中開頭的 "0" 的數量:
intsize_2_bin(size_t s){if(s <=8)return0;if(s <=320){// Number of leading zeros in s.int z =clz(s);// Round up to the relevant// power of 2.size_t r = s +(1ul<<(61- z))-1;int y =clz(r);// y indicates which power of two.// r shifted and masked indicates// what the low-order bits are.return4*(60- y)+((r >>(61- y))&3);}if(s <=448)return22;if(s <=512)return23;...if(size <=1044480)return45;return45+ceil(size-1044480,4096);}
透過 setjmp / longjmp 實作 coroutine 的方式,並且實際撰寫程式來測試,他建立兩個 coroutine: A, B。
在他的測試中,setjmp 把資訊儲存於 bufferA 後執行 B routine後,再藉由 longjmp 回到當初於 A routine 中呼叫 B 的位置;藉此可以達到再兩個函式中切換;把 routine A, B 換成兩條thread,便是 thread 間維持 sequential consistency 的實作。