{"id":101737,"date":"2026-09-07T12:00:56","date_gmt":"2026-09-07T04:00:56","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/101737.html"},"modified":"2026-09-07T12:00:56","modified_gmt":"2026-09-07T04:00:56","slug":"malloc-bins-index","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/101737.html","title":{"rendered":"malloc bins index"},"content":{"rendered":"<p>\u628a\u00a0bins\u00a0\u6570\u7ec4\u60f3\u8c61\u6210\u4e00\u4e2a\u62e5\u6709 254 \u4e2a\u683c\u5b50\u7684\u5de8\u578b\u6536\u7eb3\u67dc\u3002\u6bcf\u4e2a\u683c\u5b50&#xff08;\u6216\u6bcf\u4e24\u4e2a\u683c\u5b50&#xff09;\u5c31\u662f\u4e00\u4e2a\u201c\u62bd\u5c49\u201d&#xff08;bin&#xff09;&#xff0c;\u7528\u6765\u6302\u4e00\u4e2a\u7a7a\u95f2\u5185\u5b58\u5757\u94fe\u8868\u3002\u5173\u952e\u662f&#xff0c;\u8fd9\u4e9b\u683c\u5b50\u4e0d\u662f\u968f\u610f\u4f7f\u7528\u7684&#xff0c;\u5b83\u4eec\u88ab\u4e25\u683c\u5206\u6210\u4e86\u51e0\u4e2a\u529f\u80fd\u533a\u3002<\/p>\n<hr \/>\n<h4>\u6570\u7ec4\u5e03\u5c40&#xff1a;\u4e00\u4e2a 254 \u683c\u7684\u6536\u7eb3\u67dc<\/h4>\n<p>bins\u00a0\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u00a0254&#xff08;\u5373\u00a0128 * 2 &#8211; 2&#xff09;\u3002\u4e3a\u4ec0\u4e48\u662f 254&#xff1f;\u56e0\u4e3a\u6bcf\u4e2a\u53cc\u5411\u94fe\u8868\u9700\u8981\u4e24\u4e2a\u6307\u9488&#xff08;fd\u548c\u00a0bk&#xff09;\u4f5c\u4e3a\u201c\u62bd\u5c49\u628a\u624b\u201d&#xff08;\u54e8\u5175&#xff09;&#xff0c;\u6240\u4ee5 127 \u4e2a\u94fe\u8868\u5c31\u9700\u8981 254 \u4e2a\u683c\u5b50\u3002<\/p>\n<p>\u5b83\u7684\u5e03\u5c40\u5982\u4e0b&#xff08;\u7d22\u5f15\u4ece 0 \u5f00\u59cb&#xff09;&#xff1a;<\/p>\n<table>\n<tr>\u6570\u7ec4\u7d22\u5f15 (i)\u903b\u8f91\u5206\u533a\u7528\u9014 \/ \u5bf9\u5e94\u7684\u201c\u62bd\u5c49\u201d\u6570\u91cf<\/tr>\n<tbody>\n<tr>\n<td>0\u00a0\u548c\u00a01<\/td>\n<td>Unsorted Bin<\/td>\n<td>1 \u53f7\u4e34\u65f6\u4e2d\u8f6c\u53f0&#xff08;\u552f\u4e00\u4e00\u4e2a\u4e0d\u5206\u7c7b\u7684\u62bd\u5c49&#xff09;<\/td>\n<td>1 \u4e2a<\/td>\n<\/tr>\n<tr>\n<td>2\u00a0~\u00a063<\/td>\n<td>Small Bins<\/td>\n<td>\u56fa\u5b9a\u5927\u5c0f\u8d27\u67b6&#xff08;\u6bcf\u4e2a\u683c\u5b50\u5bf9\u5e94\u4e00\u4e2a\u7cbe\u786e\u5c3a\u5bf8&#xff09;<\/td>\n<td>62 \u4e2a<\/td>\n<\/tr>\n<tr>\n<td>64\u00a0~\u00a0126<\/td>\n<td>Large Bins<\/td>\n<td>\u5927\u4ef6\u5206\u7c7b\u8d27\u67b6&#xff08;\u6bcf\u4e2a\u683c\u5b50\u8986\u76d6\u4e00\u4e2a\u5c3a\u5bf8\u8303\u56f4&#xff09;<\/td>\n<td>63 \u4e2a<\/td>\n<\/tr>\n<tr>\n<td>127<\/td>\n<td>(\u4fdd\u7559)<\/td>\n<td>\u672a\u4f7f\u7528&#xff0c;\u7528\u4e8e\u5bf9\u9f50<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h4>\u5177\u4f53\u5bf9\u5e94\u5173\u7cfb&#xff1a;\u5982\u4f55\u8ba1\u7b97\u7d22\u5f15&#xff1f;<\/h4>\n<p>\u5f53\u7a0b\u5e8f\u8bf7\u6c42\u5206\u914d\u4e00\u4e2a\u5927\u5c0f\u4e3a\u00a0sz\u00a0\u7684\u5185\u5b58\u5757\u65f6&#xff0c;ptmalloc2 \u4f1a\u901a\u8fc7\u4ee5\u4e0b\u89c4\u5219&#xff0c;\u77ac\u95f4\u7b97\u51fa\u5e94\u8be5\u53bb\u6570\u7ec4\u7684\u54ea\u4e2a\u4f4d\u7f6e&#xff1a;<\/p>\n<h5>1. Unsorted Bin&#xff1a;\u6c38\u8fdc\u5728\u00a0bins[0]\u00a0\u548c\u00a0bins[1]<\/h5>\n<ul>\n<li>\n<p>\u7279\u6b8a\u4f4d\u7f6e&#xff1a;\u5b83\u5c31\u662f\u6570\u7ec4\u7684\u201c\u7b2c\u4e00\u4e2a\u62bd\u5c49\u201d\u3002<\/p>\n<\/li>\n<li>\n<p>\u89c4\u5f8b&#xff1a;\u65e0\u8bba\u4ec0\u4e48\u5927\u5c0f\u7684\u5185\u5b58\u5757&#xff0c;\u5982\u679c\u88ab\u4e22\u8fdb Unsorted Bin&#xff0c;\u90fd\u4f1a\u6302\u5728\u8fd9\u4e2a\u56fa\u5b9a\u7684\u4f4d\u7f6e\u4e0a\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>2. Small Bin \u7684\u7cbe\u786e\u6620\u5c04&#xff08;sz\u00a0&lt;&#061; 1024 \u5b57\u8282&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u89c4\u5219&#xff1a;\u6bcf\u4e2a\u7d22\u5f15\u5bf9\u5e94\u4e00\u4e2a\u7cbe\u786e\u5927\u5c0f\u3002\u516c\u5f0f\u662f\u00a0\u903b\u8f91\u7d22\u5f15 &#061; (sz \/ 16) &#8211; 1\u3002<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8bf7\u6c42\u00a032 \u5b57\u8282&#xff1a;\u903b\u8f91\u7d22\u5f15 &#061; (32\/16) &#8211; 1 &#061; 1\u3002\u5bf9\u5e94\u7684\u6570\u7ec4\u4f4d\u7f6e\u662f\u00a0bins[2*1]\u00a0\u548c\u00a0bins[2*1&#043;1]&#xff0c;\u5373\u00a0bins[2]\u00a0\u548c\u00a0bins[3]\u3002\u8fd9\u4e2a\u62bd\u5c49\u4e13\u95e8\u6302 32 \u5b57\u8282\u7684\u7a7a\u95f2\u5757\u3002<\/p>\n<\/li>\n<li>\n<p>\u8bf7\u6c42\u00a080 \u5b57\u8282&#xff1a;\u903b\u8f91\u7d22\u5f15 &#061; (80\/16) &#8211; 1 &#061; 4\u3002\u5bf9\u5e94\u7684\u6570\u7ec4\u4f4d\u7f6e\u662f\u00a0bins[8]\u00a0\u548c\u00a0bins[9]\u3002\u8fd9\u4e2a\u62bd\u5c49\u4e13\u95e8\u6302 80 \u5b57\u8282\u7684\u7a7a\u95f2\u5757\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u89c4\u5f8b&#xff1a;Small Bin \u7684\u903b\u8f91\u7d22\u5f15\u00a0n\u00a0\u5bf9\u5e94\u6570\u7ec4\u7684\u00a02n\u00a0\u548c\u00a02n&#043;1\u00a0\u4f4d\u7f6e&#xff0c;n\u00a0\u4ece 1 \u5230 62\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>3. Large Bin \u7684\u533a\u95f4\u6620\u5c04&#xff08;sz\u00a0&gt; 1024 \u5b57\u8282&#xff09;<\/h5>\n<ul>\n<li>\n<p>\u89c4\u5219&#xff1a;\u6bcf\u4e2a\u7d22\u5f15\u8986\u76d6\u4e00\u4e2a\u5927\u5c0f\u8303\u56f4&#xff0c;\u5229\u7528\u4f4d\u8fd0\u7b97\u5feb\u901f\u5b9a\u4f4d\u3002<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b&#xff1a;\u8bf7\u6c42\u00a02048 \u5b57\u8282\u3002ptmalloc2 \u4e0d\u4f1a\u53bb\u6bd4\u8f83\u5927\u5c0f&#xff0c;\u800c\u662f\u76f4\u63a5\u7528\u4f4d\u8fd0\u7b97&#xff08;\u5982\u00a0__builtin_clz\u00a0\u8ba1\u7b97\u524d\u5bfc\u96f6&#xff09;\u5224\u65ad\u5b83\u5c5e\u4e8e\u54ea\u4e2a\u5e42\u6b21\u533a\u95f4&#xff0c;\u7136\u540e\u6620\u5c04\u5230\u5bf9\u5e94\u7684 Large Bin \u7d22\u5f15\u3002\u6bd4\u5982\u5b83\u53ef\u80fd\u88ab\u6620\u5c04\u5230\u903b\u8f91\u7d22\u5f15\u00a064&#xff0c;\u5bf9\u5e94\u6570\u7ec4\u4f4d\u7f6e\u00a0bins[128]\u00a0\u548c\u00a0bins[129]\u3002\u8fd9\u4e2a\u62bd\u5c49\u91cc\u6302\u7740\u7684\u6240\u6709\u7a7a\u95f2\u5757&#xff0c;\u5927\u5c0f\u90fd\u5728 1024~2048 \u5b57\u8282\u4e4b\u95f4&#xff0c;\u5e76\u4e14\u6309\u5927\u5c0f\u6392\u597d\u5e8f\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u4e3a\u4ec0\u4e48\u662f\u8fd9\u4e2a\u516c\u5f0f&#xff1f;\u2014\u2014 \u54e8\u5175\u8282\u70b9\u673a\u5236<\/h4>\n<p>\u4f60\u53ef\u80fd\u4f1a\u597d\u5947&#xff0c;\u4e3a\u4ec0\u4e48 Small Bin \u7684\u903b\u8f91\u7d22\u5f15\u00a01\u00a0\u5bf9\u5e94\u7684\u662f\u6570\u7ec4\u00a0bins[2]\u00a0\u800c\u4e0d\u662f\u00a0bins[1]&#xff1f;<\/p>\n<p>\u8fd9\u662f\u56e0\u4e3a\u6570\u7ec4\u7684\u6bcf\u4e2a\u201c\u62bd\u5c49\u201d\u9700\u8981\u4e24\u4e2a\u683c\u5b50\u6765\u4f5c\u4e3a\u94fe\u8868\u7684\u5934\u5c3e\u54e8\u5175\u3002\u8fd9\u4e24\u4e2a\u683c\u5b50\u672c\u8eab\u4e0d\u5b58\u6570\u636e&#xff0c;\u53ea\u5b58\u6307\u9488&#xff08;\u6307\u5411\u94fe\u8868\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u7a7a\u95f2\u5757&#xff09;\u3002<\/p>\n<ul>\n<li>\n<p>bins[2*n]&#xff1a;\u5b58\u653e\u6307\u5411\u94fe\u8868\u5934\u90e8\u7684\u6307\u9488&#xff08;fd&#xff0c;\u524d\u5411\u6307\u9488&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>bins[2*n&#043;1]&#xff1a;\u5b58\u653e\u6307\u5411\u94fe\u8868\u5c3e\u90e8\u7684\u6307\u9488&#xff08;bk&#xff0c;\u540e\u5411\u6307\u9488&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5f53\u94fe\u8868\u4e3a\u7a7a\u65f6&#xff0c;bins[2*n]\u00a0\u548c\u00a0bins[2*n&#043;1]\u00a0\u90fd\u6307\u5411\u00a0bins[2*n]\u00a0\u81ea\u8eab&#xff08;\u5373\u6307\u5411\u54e8\u5175\u672c\u8eab&#xff09;\u3002\u8fd9\u79cd\u8bbe\u8ba1\u4f7f\u5f97\u94fe\u8868\u64cd\u4f5c\u975e\u5e38\u7edf\u4e00\u548c\u9ad8\u6548\u3002<\/p>\n<hr \/>\n<h4>\u4e00\u5f20\u56fe\u770b\u61c2\u5168\u5c40\u5bf9\u5e94\u5173\u7cfb<\/h4>\n<p>bins \u6570\u7ec4 (254 \u4e2a mchunkptr \u5143\u7d20)<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 \u7d22\u5f15 0, 1  \u2500\u2500\u25ba Unsorted Bin (1 \u4e2a\u62bd\u5c49&#xff0c;\u6302\u8f7d\u4efb\u610f\u5927\u5c0f)<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 \u7d22\u5f15 2, 3  \u2500\u2500\u25ba Small Bin [1]&#xff1a;\u4e13\u95e8\u6302 32 \u5b57\u8282\u7684\u5757<br \/>\n\u251c\u2500\u2500 \u7d22\u5f15 4, 5  \u2500\u2500\u25ba Small Bin [2]&#xff1a;\u4e13\u95e8\u6302 48 \u5b57\u8282\u7684\u5757<br \/>\n\u251c\u2500\u2500 \u7d22\u5f15 6, 7  \u2500\u2500\u25ba Small Bin [3]&#xff1a;\u4e13\u95e8\u6302 64 \u5b57\u8282\u7684\u5757<br \/>\n\u2502      &#8230;<br \/>\n\u251c\u2500\u2500 \u7d22\u5f15 62, 63 \u2500\u2500\u25ba Small Bin [31]&#xff1a;\u4e13\u95e8\u6302 512 \u5b57\u8282\u7684\u5757<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 \u7d22\u5f15 64, 65 \u2500\u2500\u25ba Large Bin [64]&#xff1a;\u7ba1\u7406 1024~X \u5b57\u8282\u7684\u5757 (\u8303\u56f41)<br \/>\n\u2502      &#8230;<br \/>\n\u251c\u2500\u2500 \u7d22\u5f15 124, 125 \u2500\u2500\u25ba Large Bin [126]&#xff1a;\u7ba1\u7406\u8d85\u5927\u7684\u5757 (\u8303\u56f463)<br \/>\n\u2502<br \/>\n\u2514\u2500\u2500 \u7d22\u5f15 127    \u2500\u2500\u25ba (\u672a\u4f7f\u7528) <\/p>\n<hr \/>\n<h4>\u7ec8\u6781\u4e00\u53e5\u603b\u7ed3<\/h4>\n<p>bins\u00a0\u6570\u7ec4\u7684\u5bf9\u5e94\u5173\u7cfb\u662f&#xff1a;<\/p>\n<ul>\n<li>\n<p>Unsorted Bin\u00a0\u56fa\u5b9a\u5360\u7528\u6570\u7ec4\u7684\u00a0\u524d 2 \u4e2a\u4f4d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>Small Bin \u7684\u7d22\u5f15\u00a0n\u00a0\u5bf9\u5e94\u6570\u7ec4\u7684\u00a02n\u00a0\u548c\u00a02n&#043;1\u00a0\u4f4d\u7f6e&#xff0c;n\u00a0\u4ece 1 \u5f00\u59cb\u3002<\/p>\n<\/li>\n<li>\n<p>Large Bin \u7684\u7d22\u5f15\u00a0m\u00a0\u5bf9\u5e94\u6570\u7ec4\u7684\u00a02m\u00a0\u548c\u00a02m&#043;1\u00a0\u4f4d\u7f6e&#xff0c;m\u00a0\u4ece 64 \u5f00\u59cb\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u8bbe\u8ba1\u8ba9\u00a0malloc\u00a0\u80fd\u5728 O(1) \u65f6\u95f4\u5185&#xff0c;\u6839\u636e\u8bf7\u6c42\u5927\u5c0f\u76f4\u63a5\u8ba1\u7b97\u51fa\u76ee\u6807\u201c\u62bd\u5c49\u201d\u5728\u6570\u7ec4\u4e2d\u7684\u7cbe\u786e\u4f4d\u7f6e&#xff0c;\u4ece\u800c\u5feb\u901f\u51b3\u5b9a\u53bb\u54ea\u4e2a\u94fe\u8868\u67e5\u627e\u7a7a\u95f2\u5757\u3002<\/p>\n<\/p>\n<h4><span style=\"color:#fe2c24\">\u5171254 \u4e2a&#xff0c;\u53ea\u7528\u4e86126\u4e2a\u5417?<\/span><\/h4>\n<p>\u662f\u7684&#xff0c;\u4ece\u903b\u8f91\u4e0a\u8bf4&#xff0c;bins\u00a0\u6570\u7ec4\u7684 254 \u4e2a\u4f4d\u7f6e&#xff0c;\u771f\u6b63\u88ab\u7528\u4f5c\u72ec\u7acb\u201c\u62bd\u5c49\u201d&#xff08;\u94fe\u8868\u54e8\u5175&#xff09;\u7684\u53ea\u6709 127 \u4e2a&#xff0c;\u4e5f\u5c31\u662f\u00a0NBINS\u00a0(128) \u51cf\u53bb 1 \u4e2a\u672a\u4f7f\u7528\u7684\u3002<\/p>\n<p>\u4f46\u662f&#xff0c;\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u5269\u4e0b\u7684 127 \u4e2a\u4f4d\u7f6e\u5c31\u6d6a\u8d39\u4e86\u3002\u8fd9\u80cc\u540e\u662f\u4e00\u4e2a\u7cbe\u5999\u7684\u201c\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\u7684\u8bbe\u8ba1\u3002<\/p>\n<hr \/>\n<h4>\u4e3a\u4ec0\u4e48\u662f 254 &#061; 2 * 127&#xff1f;<\/h4>\n<p>\u8fd9\u4e2a\u516c\u5f0f\u76f4\u63a5\u8bf4\u660e\u4e86\u539f\u56e0&#xff1a;\u6bcf\u4e2a\u201c\u62bd\u5c49\u201d&#xff08;bin&#xff09;\u9700\u89812 \u4e2a\u8fde\u7eed\u7684\u6570\u7ec4\u5143\u7d20\u6765\u5145\u5f53\u53cc\u5411\u94fe\u8868\u7684\u5934\u5c3e\u54e8\u5175\u3002<\/p>\n<ul>\n<li>\n<p>127 \u4e2a\u201c\u62bd\u5c49\u201d \u00d7 \u6bcf\u4e2a\u62bd\u5c49 2 \u4e2a\u54e8\u5175 &#061;\u00a0254 \u4e2a\u6570\u7ec4\u5143\u7d20\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6240\u4ee5&#xff0c;254 \u4e2a\u4f4d\u7f6e\u5bf9\u5e94\u7684\u662f 127 \u4e2a\u62bd\u5c49\u3002<\/p>\n<hr \/>\n<h4>\u90a3 127 \u4e2a\u62bd\u5c49\u662f\u600e\u4e48\u5206\u914d\u7684&#xff1f;<\/h4>\n<p>\u8fd9 127 \u4e2a\u62bd\u5c49\u7684\u5206\u914d\u5982\u4e0b&#xff1a;<\/p>\n<table>\n<tr>\u62bd\u5c49\u7c7b\u578b\u6570\u91cf\u903b\u8f91\u7d22\u5f15\u8303\u56f4\u5bf9\u5e94\u7684\u6570\u7ec4\u4f4d\u7f6e<\/tr>\n<tbody>\n<tr>\n<td>Unsorted Bin<\/td>\n<td>1 \u4e2a<\/td>\n<td>\u65e0<\/td>\n<td>bins[0]\u00a0\u548c\u00a0bins[1]<\/td>\n<\/tr>\n<tr>\n<td>Small Bins<\/td>\n<td>62 \u4e2a<\/td>\n<td>1\u00a0\u5230\u00a062<\/td>\n<td>bins[2]\u00a0\u5230\u00a0bins[125]<\/td>\n<\/tr>\n<tr>\n<td>Large Bins<\/td>\n<td>63 \u4e2a<\/td>\n<td>64\u00a0\u5230\u00a0126<\/td>\n<td>bins[126]\u00a0\u5230\u00a0bins[251]<\/td>\n<\/tr>\n<tr>\n<td>\u672a\u4f7f\u7528<\/td>\n<td>1 \u4e2a<\/td>\n<td>127<\/td>\n<td>bins[252]\u00a0\u548c\u00a0bins[253]<\/td>\n<\/tr>\n<tr>\n<td>\u603b\u8ba1<\/td>\n<td>127 \u4e2a<\/td>\n<td>&#8211;<\/td>\n<td>254 \u4e2a\u5143\u7d20<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h4>\u4e3a\u4ec0\u4e48\u4fdd\u7559\u00a0bins[127]\u00a0\u4e0d\u7528&#xff1f;<\/h4>\n<p>Glibc \u6e90\u7801\u4e2d\u5b9a\u4e49\u00a0NBINS &#061; 128&#xff0c;\u4f46\u5b9e\u9645\u4f7f\u7528\u7684 bin \u6570\u91cf\u662f\u00a0NBINS &#8211; 1 &#061; 127\u3002\u8fd9\u770b\u8d77\u6765\u786e\u5b9e\u6709\u70b9\u6d6a\u8d39&#xff0c;\u4e3b\u8981\u6709\u4e24\u4e2a\u539f\u56e0&#xff1a;<\/p>\n<li>\n<p>\u5386\u53f2\u4e0e\u517c\u5bb9\u6027&#xff1a;dlmalloc\u00a0\u548c\u65e9\u671f\u7684 ptmalloc2 \u8bbe\u8ba1\u5c31\u662f\u5982\u6b64\u3002bins[127]\u00a0\u88ab\u4fdd\u7559\u4e0b\u6765&#xff0c;\u53ef\u80fd\u662f\u4e3a\u4e86\u907f\u514d\u672a\u6765\u4fee\u6539\u00a0NBINS\u00a0\u5b9a\u4e49\u65f6\u5e26\u6765\u7684\u590d\u6742\u5f71\u54cd\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b80\u5316\u7d22\u5f15\u8ba1\u7b97&#xff1a;\u4fdd\u7559\u4e00\u4e2a\u672a\u4f7f\u7528\u7684 bin&#xff0c;\u53ef\u4ee5\u8ba9 Small\/Large Bin \u7684\u7d22\u5f15\u8ba1\u7b97\u903b\u8f91\u4fdd\u6301\u7b80\u6d01\u548c\u4e00\u81f4\u6027\u3002\u4f8b\u5982&#xff0c;bin_at(m, i)\u00a0\u5b8f\u53ef\u4ee5\u5b89\u5168\u5730\u5904\u7406\u00a0i\u00a0\u4ece 0 \u5230\u00a0NBINS-1\u00a0\u7684\u6240\u6709\u503c&#xff0c;\u800c\u65e0\u9700\u989d\u5916\u68c0\u67e5\u8fb9\u754c\u3002<\/p>\n<\/li>\n<hr \/>\n<h4>\u603b\u7ed3&#xff1a;\u5e76\u975e\u6d6a\u8d39&#xff0c;\u800c\u662f\u7d22\u5f15\u7684\u5bf9\u9f50\u9700\u8981<\/h4>\n<ul>\n<li>\n<p>254 \u4e2a\u4f4d\u7f6e\u662f 127 \u4e2a\u62bd\u5c49\u7684\u7269\u7406\u5b9e\u73b0&#xff0c;\u6bcf\u4e2a\u62bd\u5c49\u9700\u8981\u4e00\u5bf9\u54e8\u5175\u3002<\/p>\n<\/li>\n<li>\n<p>\u903b\u8f91\u4e0a&#xff0c;\u53ea\u6709 127 \u4e2a\u62bd\u5c49\u88ab\u4f7f\u7528&#xff0c;bins[127]\u00a0\u662f\u4fdd\u7559\u7684\u201c\u7a7a\u4f4d\u201d\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fd9\u4e2a\u7a7a\u4f4d\u4e0d\u662f\u6d6a\u8d39&#xff0c;\u5b83\u5141\u8bb8\u4ee3\u7801\u5c06\u6240\u6709\u7684\u201c\u62bd\u5c49\u201d\u4ece\u00a0bins[0]\u00a0\u5230\u00a0bins[127]\u00a0\u7edf\u4e00\u7d22\u5f15&#xff0c;\u7b80\u5316\u4e86\u6570\u7ec4\u8fb9\u754c\u68c0\u67e5\u7684\u4ee3\u7801\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6240\u4ee5&#xff0c;\u7406\u89e3\u201c\u53ea\u7528\u4e86 126 \u4e2a\u201d&#xff0c;\u53ea\u4e0d\u8fc7\u5b9e\u9645\u4e0a\u662f\u6709 1 \u4e2a Unsorted Bin &#043; 62 \u4e2a Small Bins &#043; 63 \u4e2a Large Bins &#061;\u00a0126 \u4e2a\u903b\u8f91\u4e0a\u72ec\u7acb\u7684\u201c\u529f\u80fd\u5206\u533a\u201d&#xff0c;\u4f46\u5b83\u4eec\u5728\u6570\u7ec4\u91cc\u7684\u201c\u62bd\u5c49\u201d&#xff08;\u54e8\u5175\u5bf9&#xff09;\u6570\u91cf\u662f 127 \u4e2a&#xff0c;\u56e0\u4e3a\u8fd8\u6709\u4e00\u4e2a\u672a\u4f7f\u7528\u7684\u4fdd\u7559\u62bd\u5c49\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u628a\u00a0bins\u00a0\u6570\u7ec4\u60f3\u8c61\u6210\u4e00\u4e2a\u62e5\u6709 254 \u4e2a\u683c\u5b50\u7684\u5de8\u578b\u6536\u7eb3\u67dc\u3002\u6bcf\u4e2a\u683c\u5b50&#xff08;\u6216\u6bcf\u4e24\u4e2a\u683c\u5b50&#xff09;\u5c31\u662f\u4e00\u4e2a\u201c\u62bd\u5c49\u201d&#xff08;bin&#xff09;&#xff0c;\u7528\u6765\u6302\u4e00\u4e2a\u7a7a\u95f2\u5185\u5b58\u5757\u94fe\u8868\u3002\u5173\u952e\u662f&#xff0c;\u8fd9\u4e9b\u683c\u5b50\u4e0d\u662f\u968f\u610f\u4f7f\u7528\u7684&#xff0c;\u5b83\u4eec\u88ab\u4e25\u683c\u5206\u6210\u4e86\u51e0\u4e2a\u529f\u80fd\u533a\u3002 \u6570\u7ec4\u5e03\u5c40&#xff1a;\u4e00\u4e2a 254 \u683c\u7684\u6536\u7eb3\u67dc<br \/>\nbins\u00a0\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u00a0254&#xff08;\u5373\u00a0128 * 2 &#8211; 2&#xff09;\u3002\u4e3a\u4ec0\u4e48\u662f 254&#xff1f;\u56e0\u4e3a\u6bcf<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58],"topic":[],"class_list":["post-101737","post","type-post","status-publish","format-standard","hentry","category-server","tag-linux"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>malloc bins index - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/101737.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"malloc bins index - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u628a\u00a0bins\u00a0\u6570\u7ec4\u60f3\u8c61\u6210\u4e00\u4e2a\u62e5\u6709 254 \u4e2a\u683c\u5b50\u7684\u5de8\u578b\u6536\u7eb3\u67dc\u3002\u6bcf\u4e2a\u683c\u5b50&#xff08;\u6216\u6bcf\u4e24\u4e2a\u683c\u5b50&#xff09;\u5c31\u662f\u4e00\u4e2a\u201c\u62bd\u5c49\u201d&#xff08;bin&#xff09;&#xff0c;\u7528\u6765\u6302\u4e00\u4e2a\u7a7a\u95f2\u5185\u5b58\u5757\u94fe\u8868\u3002\u5173\u952e\u662f&#xff0c;\u8fd9\u4e9b\u683c\u5b50\u4e0d\u662f\u968f\u610f\u4f7f\u7528\u7684&#xff0c;\u5b83\u4eec\u88ab\u4e25\u683c\u5206\u6210\u4e86\u51e0\u4e2a\u529f\u80fd\u533a\u3002 \u6570\u7ec4\u5e03\u5c40&#xff1a;\u4e00\u4e2a 254 \u683c\u7684\u6536\u7eb3\u67dc bins\u00a0\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u00a0254&#xff08;\u5373\u00a0128 * 2 - 2&#xff09;\u3002\u4e3a\u4ec0\u4e48\u662f 254&#xff1f;\u56e0\u4e3a\u6bcf\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/101737.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-07T04:00:56+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/101737.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/101737.html\",\"name\":\"malloc bins index - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-07T04:00:56+00:00\",\"dateModified\":\"2026-09-07T04:00:56+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/101737.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/101737.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/101737.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"malloc bins index\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"malloc bins index - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/101737.html","og_locale":"zh_CN","og_type":"article","og_title":"malloc bins index - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u628a\u00a0bins\u00a0\u6570\u7ec4\u60f3\u8c61\u6210\u4e00\u4e2a\u62e5\u6709 254 \u4e2a\u683c\u5b50\u7684\u5de8\u578b\u6536\u7eb3\u67dc\u3002\u6bcf\u4e2a\u683c\u5b50&#xff08;\u6216\u6bcf\u4e24\u4e2a\u683c\u5b50&#xff09;\u5c31\u662f\u4e00\u4e2a\u201c\u62bd\u5c49\u201d&#xff08;bin&#xff09;&#xff0c;\u7528\u6765\u6302\u4e00\u4e2a\u7a7a\u95f2\u5185\u5b58\u5757\u94fe\u8868\u3002\u5173\u952e\u662f&#xff0c;\u8fd9\u4e9b\u683c\u5b50\u4e0d\u662f\u968f\u610f\u4f7f\u7528\u7684&#xff0c;\u5b83\u4eec\u88ab\u4e25\u683c\u5206\u6210\u4e86\u51e0\u4e2a\u529f\u80fd\u533a\u3002 \u6570\u7ec4\u5e03\u5c40&#xff1a;\u4e00\u4e2a 254 \u683c\u7684\u6536\u7eb3\u67dc bins\u00a0\u6570\u7ec4\u7684\u5927\u5c0f\u662f\u00a0254&#xff08;\u5373\u00a0128 * 2 - 2&#xff09;\u3002\u4e3a\u4ec0\u4e48\u662f 254&#xff1f;\u56e0\u4e3a\u6bcf","og_url":"https:\/\/www.wsisp.com\/helps\/101737.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-07T04:00:56+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/101737.html","url":"https:\/\/www.wsisp.com\/helps\/101737.html","name":"malloc bins index - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-07T04:00:56+00:00","dateModified":"2026-09-07T04:00:56+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/101737.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/101737.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/101737.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"malloc bins index"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/101737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=101737"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/101737\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=101737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=101737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=101737"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=101737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}