x = malloc(4) y = malloc(9) m = malloc(5) z = malloc(4) n = malloc(2) w = malloc(11) o = malloc(8) a = malloc(4) p = malloc(4) b = malloc(9) q = malloc(8) c = malloc(2) free(m); free(n); free(o); free(p); free(q); Supposing the heap starts at address 100000, and is of size 1000. freelist[n] says where the first free chunk of size 4n+8 is. freelist[0]: 100020 = address of first free size 8 chunk freelist[1]: 100060 = address of first free size 12 chunk freelist[2]: 0 = there are no free size 16 chunks freelist[3]: 0 = there are no free size 20 chunks . . . freelist[217]: 0 = there are no free size 876 chunks freelist[218]: 100120 = address of first free size 880 chunk freelist[219]: 0 = there are no free size 884 chunks . . . freelist[10000]: 0 = there are no free size 40008 chunks freelist[10001]: 0 = there are no free chunks bigger than 40008 words 12121212 = the special pattern that marks an "in use" chunk 98989898 = the special pattern that marks a free chunk. ________________________ 100000: 8 = size of chunk 100001: 12121212 = "used" 100002: x0 100003: x1 100004: x2 100005: x3 100006: - 100007: 8 = size of chunk _______________________ 100008: 12 = size of chunk 100009: 12121212 = "used" 100010: y0 100011: y1 100012: y2 100013: y3 100014: y4 100015: y5 100016: y6 100017: y7 100018: y8 100019: 12 = size of chunk _______________________ 100020: 8 = size of chunk 100021: 98989898 = "free" 100022: 100036 = address of next size 8 free chunk 100023: 0 = no previous size 8 free chunk 100024: - 100025: - 100026: - 100027: 8 = size of chunk ________________________ 100028: 8 = size of chunk 100029: 12121212 = "used" 100030: z0 100031: z1 100032: z2 100033: z3 100034: - 100035: 8 = size of chunk ________________________ 100036: 8 = size of chunk 100037: 98989898 = "free" 100038: 100080 = address of next size 8 free chunk 100039: 100020 = address of previous size 8 free chunk 100040: - 100041: - 100042: - 100043: 8 = size of chunk ________________________ 100044: 16 = size of chunk 100045: 12121212 = "used" 100046: w0 100047: w1 100048: w2 100049: w3 100050: w4 100051: w5 100052: w6 100053: w7 100054: w8 100055: w9 100056: w10 100057: - 100058: - 100059: 16 = size of chunk ________________________ 100060: 12 = size of chunk 100061: 98989898 = "free" 100062: 100100 = address of next size 12 free chunk 100063: 0 = no previous size 12 free chunk 100064: - 100065: - 100066: - 100067: - 100068: - 100069: - 100070: - 100071: 12 = size of chunk _______________________ 100072: 8 = size of chunk 100073: 12121212 = "used" 100074: a0 100075: a1 100076: a2 100077: a3 100078: - 100079: 8 = size of chunk _______________________ 100080: 8 = size of chunk 100081: 98989898 = "free" 100082: 0 = no next size 8 free chunk 100083: 100036 = address of previous size 8 free chunk 100084: - 100085: - 100086: - 100087: 8 = size of chunk _______________________ 100088: 12 = size of chunk 100089: 12121212 = "used" 100090: b0 100091: b1 100092: b2 100093: b3 100094: b4 100095: b5 100096: b6 100097: b7 100098: b8 100099: 12 = size of chunk _____________________ 000100: 12 = size of chunk 000101: 98989898 = "free" 000102: 0 = no next size 12 free chunk 000103: 100060 = address of previous size 12 chunk 000104: - 000105: - 000106: - 000107: - 000108: - 000109: - 000110: - 000111: 12 = size of chunk ____________________ 000112: 8 = size of chunk 000113: 12121212 = "used" 000114: c0 000115: c1 000116: - 000117: - 000118: - 000119: 8 = size of chunk _____________________ 000120: 880 = size of chunk 000121: 98989898 = "free" 000122: 0 = no next size 880 free chunk 000123: 0 = no previous size 880 free chunk 000124: - 000125: - 000126: - 000127: - 000128: - 000129: - 000130: - 000131: - 000132: - 000133: - 000134: - 000135: - 000136: - 000137: - 000138: - 000139: - 000140: - 000141: - 000142: - 000143: - 000144: - 000145: - 000146: - 000147: - 000148: - 000149: - 000150: - 000151: - 000152: - 000153: - 000154: - 000155: - 000156: - 000157: - 000158: - 000159: - 000160: - 000161: - 000162: - 000163: - 000164: - 000165: - 000166: - 000167: - 000168: - 000169: - 000170: - 000171: - 000172: - 000173: - 000174: - 000175: - 000176: - 000177: - 000178: - 000179: - 000180: - 000181: - 000182: 000183: 000184: 000185: 000186: 000187: 000188: 000189: 000190: 000191: 000192: 000193: 000194: 000195: 000196: 000197: 000198: 000199: 000200: 000201: 000202: 000203: 000204: 000205: 000206: 000207: 000208: 000209: 000210: 000211: 000212: 000213: 000214: 000215: 000216: 000217: 000218: 000219: 000220: 000221: 000222: 000223: 000224: 000225: 000226: 000227: 000228: 000229: 000230: 000231: 000232: 000233: 000234: 000235: 000236: 000237: 000238: 000239: 000240: 000241: 000242: 000243: 000244: 000245: 000246: 000247: 000248: 000249: 000250: 000251: 000252: 000253: 000254: 000255: 000256: 000257: 000258: 000259: 000260: 000261: 000262: 000263: 000264: 000265: 000266: 000267: 000268: 000269: 000270: 000271: 000272: 000273: 000274: 000275: 000276: 000277: 000278: 000279: 000280: 000281: 000282: 000283: 000284: 000285: 000286: 000287: 000288: 000289: 000290: 000291: 000292: 000293: 000294: 000295: 000296: 000297: 000298: 000299: 000300: 000301: 000302: 000303: 000304: 000305: 000306: 000307: 000308: 000309: 000310: 000311: 000312: 000313: 000314: 000315: 000316: 000317: 000318: 000319: 000320: 000321: 000322: 000323: 000324: 000325: 000326: 000327: 000328: 000329: 000330: 000331: 000332: 000333: 000334: 000335: 000336: 000337: 000338: 000339: 000340: 000341: 000342: 000343: 000344: 000345: 000346: 000347: 000348: 000349: 000350: 000351: 000352: 000353: 000354: 000355: 000356: 000357: 000358: 000359: 000360: 000361: 000362: 000363: 000364: 000365: 000366: 000367: 000368: 000369: 000370: 000371: 000372: 000373: 000374: 000375: 000376: 000377: 000378: 000379: 000380: 000381: 000382: 000383: 000384: 000385: 000386: 000387: 000388: 000389: 000390: 000391: 000392: 000393: 000394: 000395: 000396: 000397: 000398: 000399: 000400: 000401: 000402: 000403: 000404: 000405: 000406: 000407: 000408: 000409: 000410: 000411: 000412: 000413: 000414: 000415: 000416: 000417: 000418: 000419: 000420: 000421: 000422: 000423: 000424: 000425: 000426: 000427: 000428: 000429: 000430: 000431: 000432: 000433: 000434: 000435: 000436: 000437: 000438: 000439: 000440: 000441: 000442: 000443: 000444: 000445: 000446: 000447: 000448: 000449: 000450: 000451: 000452: 000453: 000454: 000455: 000456: 000457: 000458: 000459: 000460: 000461: 000462: 000463: 000464: 000465: 000466: 000467: 000468: 000469: 000470: 000471: 000472: 000473: 000474: 000475: 000476: 000477: 000478: 000479: 000480: 000481: 000482: 000483: 000484: 000485: 000486: 000487: 000488: 000489: 000490: 000491: 000492: 000493: 000494: 000495: 000496: 000497: 000498: 000499: 000500: 000501: 000502: 000503: 000504: 000505: 000506: 000507: 000508: 000509: 000510: 000511: 000512: 000513: 000514: 000515: 000516: 000517: 000518: 000519: 000520: 000521: 000522: 000523: 000524: 000525: 000526: 000527: 000528: 000529: 000530: 000531: 000532: 000533: 000534: 000535: 000536: 000537: 000538: 000539: 000540: 000541: 000542: 000543: 000544: 000545: 000546: 000547: 000548: 000549: 000550: 000551: 000552: 000553: 000554: 000555: 000556: 000557: 000558: 000559: 000560: 000561: 000562: 000563: 000564: 000565: 000566: 000567: 000568: 000569: 000570: 000571: 000572: 000573: 000574: 000575: 000576: 000577: 000578: 000579: 000580: 000581: 000582: 000583: 000584: 000585: 000586: 000587: 000588: 000589: 000590: 000591: 000592: 000593: 000594: 000595: 000596: 000597: 000598: 000599: 000600: 000601: 000602: 000603: 000604: 000605: 000606: 000607: 000608: 000609: 000610: 000611: 000612: 000613: 000614: 000615: 000616: 000617: 000618: 000619: 000620: 000621: 000622: 000623: 000624: 000625: 000626: 000627: 000628: 000629: 000630: 000631: 000632: 000633: 000634: 000635: 000636: 000637: 000638: 000639: 000640: 000641: 000642: 000643: 000644: 000645: 000646: 000647: 000648: 000649: 000650: 000651: 000652: 000653: 000654: 000655: 000656: 000657: 000658: 000659: 000660: 000661: 000662: 000663: 000664: 000665: 000666: 000667: 000668: 000669: 000670: 000671: 000672: 000673: 000674: 000675: 000676: 000677: 000678: 000679: 000680: 000681: 000682: 000683: 000684: 000685: 000686: 000687: 000688: 000689: 000690: 000691: 000692: 000693: 000694: 000695: 000696: 000697: 000698: 000699: 000700: 000701: 000702: 000703: 000704: 000705: 000706: 000707: 000708: 000709: 000710: 000711: 000712: 000713: 000714: 000715: 000716: 000717: 000718: 000719: 000720: 000721: 000722: 000723: 000724: 000725: 000726: 000727: 000728: 000729: 000730: 000731: 000732: 000733: 000734: 000735: 000736: 000737: 000738: 000739: 000740: 000741: 000742: 000743: 000744: 000745: 000746: 000747: 000748: 000749: 000750: 000751: 000752: 000753: 000754: 000755: 000756: 000757: 000758: 000759: 000760: 000761: 000762: 000763: 000764: 000765: 000766: 000767: 000768: 000769: 000770: 000771: 000772: 000773: 000774: 000775: 000776: 000777: 000778: 000779: 000780: 000781: 000782: 000783: 000784: 000785: 000786: 000787: 000788: 000789: 000790: 000791: 000792: 000793: 000794: 000795: 000796: 000797: 000798: 000799: 000800: 000801: 000802: 000803: 000804: 000805: 000806: 000807: 000808: 000809: 000810: 000811: 000812: 000813: 000814: 000815: 000816: 000817: 000818: 000819: 000820: 000821: 000822: 000823: 000824: 000825: 000826: 000827: 000828: 000829: 000830: 000831: 000832: 000833: 000834: 000835: 000836: 000837: 000838: 000839: 000840: 000841: 000842: 000843: 000844: 000845: 000846: 000847: 000848: 000849: 000850: 000851: 000852: 000853: 000854: 000855: 000856: 000857: 000858: 000859: 000860: 000861: 000862: 000863: 000864: 000865: 000866: 000867: 000868: 000869: 000870: 000871: 000872: 000873: 000874: 000875: 000876: 000877: 000878: 000879: 000880: 000881: 000882: 000883: 000884: 000885: 000886: 000887: 000888: 000889: 000890: 000891: 000892: 000893: 000894: 000895: 000896: 000897: 000898: 000899: 000900: 000901: 000902: 000903: 000904: 000905: 000906: 000907: 000908: 000909: 000910: 000911: 000912: 000913: 000914: 000915: 000916: 000917: 000918: 000919: 000920: 000921: 000922: 000923: 000924: 000925: 000926: 000927: 000928: 000929: 000930: 000931: 000932: 000933: 000934: 000935: 000936: 000937: 000938: 000939: - 000940: - 000941: - 000942: - 000943: - 000944: - 000945: - 000946: - 000947: - 000948: - 000949: - 000950: - 000951: - 000952: - 000953: - 000954: - 000955: - 000956: - 000957: - 000958: - 000959: - 000960: - 000961: - 000962: - 000963: - 000964: - 000965: - 000966: - 000967: - 000968: - 000969: - 000970: - 000971: - 000972: - 000973: - 000974: - 000975: - 000976: - 000977: - 000978: - 000979: - 000980: - 000981: - 000982: - 000983: - 000984: - 000985: - 000986: - 000987: - 000988: - 000989: - 000990: - 000991: - 000992: - 000993: - 000994: - 000995: - 000996: - 000997: - 000998: - 000999: 880 = size of chunk _______________