10
20
30
40
50
60
70
80
90
100 :
110
120
130
140 :
150 :
160 DEFFNm_alloc(size%):LOCALA%,B%,E%:m_heap%=m_heap% :
170 IFm_heap%=0:PROCm_free(0) :
180 size%=(size%+3)AND-4:DIME%-1:IFsize%=0:=HIMEM-E%-1280 :
190 A%=m_heap%
200 IFA%:IF!A%<=size%:IFA%+!A%+4=E%:DIME%size%-!A%:!A%=size%:m_heap%=A%!4:=A%+4 :
210 IFA%:IF!A%< size%:REPEATB%=A%:A%=A%!4:UNTIL!A%>=size%ORA%=0 :
220 IFA%=0:IFHIMEM-E%-size%-1280<0:=0 :
230 IFA%=0:DIMA%size%+3:!A%=size%:=A%+4 :
240 :
250 IF!A%>size%+7:A%!(size%+8)=A%!4:A%!(size%+4)=!A%-size%-4:A%!4=A%+size%+4:!A%=size%
260 IFB%:B%!4=A%!4 ELSE m_heap%=A%!4 :
270 =A%+4 :
280 :
290 DEFPROCm_free(ptr%):m_heap%=m_heap%:IFptr%=0:ENDPROC
300 !ptr%=m_heap%:m_heap%=ptr%-4
310 IF!ptr%=ptr%+ptr%!-4:ptr%!-4=ptr%!-4+!!ptr%+4:!ptr%=!(!ptr%+4)
320 ENDPROC
330 :
340 DEFFNm_realloc(ptr%,size%):PROCm_free(ptr%):=FNm_alloc(size%)
350 :
360 DEFFNm_zalloc(size%):LOCALA%:A%=FNm_alloc(size%):IFA%=0ORsize%<1:=A%
370 REPEATsize%=size%-1:A%?size%=0:UNTILsize%<0:=A%