10
20
30 :
40 test%=3
50 :
60 IF test%=1:LIBRARY "MallocA/sr"
70 IF test%=2:LIBRARY "MallocB/sr"
80 IF test%=3:LIBRARY "MallocC/sr"
90 IF test%=0:IF PAGE>&FFFF:LIBRARY @lib$+"MAlloc.bbc"
100 IF test%=0:IF PAGE<&FFFF:LIBRARY "%.^.Library.BLib.MAlloc"
110 IF HIMEM>&FFFF:HIMEM=LOMEM+&4000
120 VDU 26,12,20:x%=0:size%=0:step%=1:claimed%=2
130 :
140 small%=0:heapend%=0:DIM heapbot% -1 :
150 REPEAT
160 DIM heapend% -1
170 PRINTCHR$30;"Claimed: ";claimed%;" Used: ";heapend%-heapbot%;" Leaked: ";(heapend%-heapbot%)-claimed%;:IFclaimed%:PRINT" Overhead: ";INT(100*((heapend%-heapbot%)/claimed%)-100);"% ";
180 GCOL 0,1:PLOT 69,x%,claimed%/16 :IFx%=&300:VDU 5,11:PRINT"claimed";CHR$4;
190 GCOL 0,3:PLOT 69,x%,(heapend%-heapbot%)/16 :IFx%=&320:VDU 5,11:PRINT"used";CHR$4;
200 GCOL 0,5:PLOT 69,x%,((heapend%-heapbot%)-claimed%)/16:IFx%=&340:VDU 5,11:PRINT"leaked";CHR$4;
210 GCOL 0,7:PLOT 69,x%,((heapend%-heapbot%)/claimed%)*40:IFx%=&360:VDU 5,11:PRINT"overhead";CHR$4;
220 :
230
240 small%=FNm_alloc(12) :IFsmall%:claimed%=claimed%+12
250 :
260
270 size%=size%+step%
280 big%=FNm_alloc(size%):IFbig%:claimed%=claimed%+size%
290 :
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440 :
450 x%=x%+2
460 PRINT'"small%=";~small%;" big%=";~big%;" size%=";~size%;" "
470 PROCheap
480 UNTIL x%>&800 OR size%<1:PRINT'
490 END
500 :
510 DEFPROCheap:PRINTSPC6"Addr"SPC6"Size"SPC6"Link"
520 A%=m_heap%:REPEAT
530 PRINT~A%;:IF A%:PRINT~!A%,~A%!4;:A%=A%!4
540 PRINT:UNTIL A%=0 OR VPOS>20:PRINTSPC30:ENDPROC
550 :