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+&3000
120 VDU 26,12,20:x%=0:size%=32:step%=16:fix%=step%-4:claimed%=2
130
140 :
150 big%=FNm_alloc(size%):claimed%=size% :
160 small%=0:heapend%=0:DIM heapbot% -1 :
170 REPEAT
180 DIM heapend% -1
190 PRINTCHR$30;"Claimed: ";claimed%;" Used: ";heapend%-heapbot%;" Leaked: ";(heapend%-heapbot%)-claimed%;:IFclaimed%:PRINT" Overhead: ";INT(100*((heapend%-heapbot%)/claimed%)-100);"% ";
200 GCOL 0,1:PLOT 69,x%,claimed%/16 :IFx%=&300:VDU5,11:PRINT"claimed";CHR$4;
210 GCOL 0,3:PLOT 69,x%,(heapend%-heapbot%)/16 :IFx%=&320:VDU5,11:PRINT"used";CHR$4;
220 GCOL 0,5:PLOT 69,x%,((heapend%-heapbot%)-claimed%)/16:IFx%=&340:VDU5,11:PRINT"leaked";CHR$4;
230 GCOL 0,7:PLOT 69,x%,((heapend%-heapbot%)/claimed%)*40:IFx%=&360:VDU5,11:PRINT"overhead";CHR$4;
240 :
250
260 small%=FNm_alloc(fix%):IFsmall%:claimed%=claimed%+fix%
270 :
280
290 PROCm_free(big%) :IFbig%:claimed%=claimed%-size%
300 :
310
320 size%=size%+step%
330 big%=FNm_alloc(size%):IFbig%:claimed%=claimed%+size%
340 :
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500 :
510 x%=x%+2
520 PRINT'"small%=";~small%;" big%=";~big%;" size%=";~size%;" "
530 PROCheap
540 UNTIL x%>&800 OR size%<8:PRINT'
550 END
560 :
570 DEFPROCheap:PRINTSPC6"Addr"SPC6"Size"SPC6"Link"
580 A%=m_heap%:REPEAT
590 PRINT~A%;:IF A%:PRINT~!A%,~A%!4;:A%=A%!4
600 PRINT:UNTIL A%=0 OR VPOS>20:PRINTSPC30:ENDPROC
610 :